2012-01-06 66 views
4

我有我的Account模型中定義的簡單思維獅身人面像指數:(忽略三角洲現在,我生成了完整的索引和搜索account_core爲什麼我的索引缺少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.count 
# => 885138 

>> Account.search.total_entries 
# => 260795 

>> Account.search("[email protected]") 
# => [] 

然而,在命令行上,使用search實用,我能找到倫尼:

$ search -c /etc/sphinx/water.sphinx.conf -i account_core [email protected] 

index 'account_core': query '[email protected] ': 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 

確實這些都是德魯的賬戶ID。

爲什麼我在使用Thinking Sphinx進行搜索時無法找到Lenny?爲什麼total_entries號碼比accounts表中的總行數小得多?

回答

1

事實證明,這個問題與Thinking Sphinx如何處理Single Table Inheritance有關。 TS僅返回對應於其中一個父類的子類的type的記錄。如果typeNULL,則文檔不包含在搜索結果中。我們在accounts表中有很多記錄,其中type=NULL。修復數據後,搜索現在按預期工作。

感謝#sphinxsearch中的roman3x指向我。