2011-05-19 47 views
6

我在我的rails應用程序中實現了sphinx搜索。
我想用模糊搜索。它應該搜索拼寫錯誤,例如,如果輸入搜索查詢charact * a * ristics,它應該搜索charact * e * ristics。思維獅身人面像模糊搜索?

我應該如何實現這個

回答

6

獅身人面像不會自然地允許拼寫錯誤 - 它不關心拼寫是否正確,它只是索引它們並匹配它們。

有兩種選擇 - 使用thinking-sphinx-raspell來捕捉用戶在搜索時的拼寫錯誤,併爲他們提供用改進的查詢再次搜索的選擇(與Google很像);或者可能使用soundex或metaphone形態,這樣就可以用一種說明它們的聲音的方式對單詞進行索引。在this page上搜索詞幹,你會找到相關章節。關於這個問題,也請閱讀Sphinx's documentation

我不知道這兩個選項有多可靠 - 個人而言,我會選擇#1。

+0

感謝拍拍, 我想用raspell的,但不適合我再quirements。我正在閱讀電子郵件內容並通過電子郵件搜索可能的產品名稱。我無法使用更正的選項來提示用戶。與raspell它碰巧它將一些縮寫名稱替換爲不相關的替代品,如用蓋子取代了LED(LED)。 也試圖用soundex和metaphone,它改善了我的結果,但不準確。 – Pravin 2011-05-20 06:44:59

2

是的,獅身人面像通常使用擴展匹配模式。

有可用下列匹配模式:

SPH_MATCH_ALL, matches all query words (default mode); 
SPH_MATCH_ANY, matches any of the query words; 
SPH_MATCH_PHRASE, matches query as a phrase, requiring perfect match; 
SPH_MATCH_BOOLEAN, matches query as a boolean expression (see Section 5.2, 「Boolean query syntax」); 
SPH_MATCH_EXTENDED, matches query as an expression in Sphinx internal query language (see Section 5.3, 「Extended query syntax」); 
SPH_MATCH_EXTENDED2, an alias for SPH_MATCH_EXTENDED; 
SPH_MATCH_FULLSCAN, matches query, forcibly using the "full scan" mode as below. NB, any query terms will be ignored, such that filters, filter-ranges and grouping will still be applied, but no text-matching. 

期間0.9.8和0.9.9的開發週期,使用SPH_MATCH_EXTENDED2當內部匹配引擎被改寫(用於附加功能和更好起見性能)。通過0.9.9版本,舊版本被刪除,SPH_MATCH_EXTENDED和SPH_MATCH_EXTENDED2現在只是別名。

enable_star

啓用星號語法(或通配符語法)通過前綴搜索時/中綴索引。 >可選,默認值爲0(不要使用通配符語法),以便與0.9.7兼容。 >已知的值是0和1。

例如,假設索引用綴內置和enable_star是1搜索應該工作如下:

"abcdef" query will match only those documents that contain the exact "abcdef" word in them. 
"abc*" query will match those documents that contain any words starting with "abc" (including the documents which contain the exact "abc" word only); 
"*cde*" query will match those documents that contain any words which have "cde" characters in any part of the word (including the documents which contain the exact "cde" word only). 
"*def" query will match those documents that contain any words ending with "def" (including the documents that contain the exact "def" word only). 

實施例:

enable_star = 1

相關問題