Thinking sphinx search returns nothing when multiple index files used on a single model

Thinking sphinx search returns nothing when multiple index files used on a single model

当我的 sphinx 索引在一个模型中被分成多个文件时,有时搜索没有结果。

我使用的版本:

我在这个模型上有五个索引:

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

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

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

但是,有时将特定于字段的查询与通用查询结合起来return没什么:

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

如果 "some string" 在 tag 字段中(在同一个索引文件中定义),它会起作用。如果它在 name 字段中(在不同的索引文件中定义),则不起作用。

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

编辑

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

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

文档因此平均分布在五个 sphinx 索引文件中,没有一个文档存在于多个索引文件中。