当在单个模型上使用多个索引文件时,认为sphinx搜索不会返回任何结果 [英] Thinking sphinx search returns nothing when multiple index files used on a single model

查看:0
本文介绍了当在单个模型上使用多个索引文件时,认为sphinx搜索不会返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的狮身人面像索引被分成一个模型中的多个文件时,搜索有时不会产生任何结果。

我使用的版本:

  • rails-4.1
  • 思考Sphinx-3.0.6
  • Sphinx-2.0.9

我对此模型有五个指标:

ThinkingSphinx::Index.define :incident, name: "incident_index_1" ... do
  indexes name
end

ThinkingSphinx::Index.define :incident, name: "incident_index_5" ... do
  indexes tags.name, as: :tag      
  indexes custom_fields_values.value, as: :custom
end

单独搜索,查询返回正确结果:

Incident.search(conditions: { custom: "dd" })
Incident.search("some string")

但是,将特定于字段的查询与通用查询组合有时不会返回任何结果:

Incident.search("some string", conditions: { custom: "dd" })

如果tag字段中有"某些字符串"(在同一索引文件中定义),则它可以工作。如果它在name字段中(在不同的索引文件中定义),则它不起作用。

推荐答案

As clarified via discussions on the Sphinx forums,这里的问题是字段位于不同的索引中,而Sphinx文档(索引中的记录,在Sphinx/Rails上下文中是ActiveRecord模型实例)应该只存在于一个Sphinx索引中,而不是分布在多个索引中。

编辑

要在SO中完成此处的答案并使问题成为独立问题,索引现在如下所示:

(1..5).each do |ind|
  ThinkingSphinx::Index.define :incident, name: "incident_index_#{ind}" ... do
    where "incidents.id % 5 = #{ind - 1}"
    indexes ...
    has ...
end

因此,文档平均分布在五个Shinx索引文件中,而一个文档不存在于多个索引文件中。

这篇关于当在单个模型上使用多个索引文件时,认为sphinx搜索不会返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆