我在 Account 模型上定义了一个简单的 Thinking Sphinx 索引:

define_index do
  indexes display_name
  indexes email_addresses.email_address

  has created_at
  set_property :delta => :datetime, :threshold => 2.minutes
end

(暂时忽略增量;我正在生成完整索引并搜索 account_core 。)

但我得到了一些意想不到的结果:
>> Account.count
# => 885138

>> Account.search.total_entries
# => 260795

>> Account.search("lenny@paperlesspost.com")
# => []

但是,在命令行上,使用 search 实用程序,我可以找到 Lenny:
$ search -c /etc/sphinx/water.sphinx.conf -i account_core drew@example.com

index 'account_core': query 'drew@example.com.com ': returned 2 matches of 2 total in 0.759 sec

displaying matches:
1. document=3543432, weight=4, sphinx_internal_id=442101, sphinx_deleted=0, class_crc=0, created_at=Mon Apr 11 12:18:08 2011
2. document=5752816, weight=2, sphinx_internal_id=719552, sphinx_deleted=0, class_crc=0, created_at=Tue Dec 27 12:01:12 2011

这些确实是 Drew 的帐户 ID。

为什么在使用 Thinking Sphinx 进行搜索时找不到 Lenny?为什么 total_entries 数比 accounts 表中的总行数小得多?

最佳答案

事实证明,这个问题与 Thinking Sphinx 如何处理单表继承有关。 TS 仅返回具有对应于父类的子类之一的 type 的记录。如果 typeNULL ,则该文档不包含在搜索结果中。我们在 accounts 表中有很多记录和 type=NULL 。修复数据后,搜索现在按预期工作。

感谢#sphinxsearch 中的roman3x 指出我这一点。

关于ruby-on-rails - 为什么我的索引缺少 Thinking Sphinx 的文档?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8764034/

10-11 22:39
查看更多