2013-04-15 46 views
0

我試圖讓ES QueryString匹配包含「and」的搜索詞,但我迄今試過的所有內容(嘗試不同的分析儀,令牌儀,過濾器)沒有工作。在MySQL方面,我要的是:ElasticSearch/Elastica:搜索包含「and」或其他停用詞的確切詞語

WHERE field LIKE '%abbot and costello%' 

我已經試過各種配置,這是我目前使用的是什麼(因爲它「方丈」匹配略有改善(與尾隨的空間),但仍然沒有它匹配任何東西「和」:

$eI->create(array(
    'analysis' => array(
     'analyzer' => array(
      'indexAnalyzer' => array(
       'type' => 'custom', 
       'tokenizer' => 'SQLedgeNGram', 
       'filter' => array(
        'lowercase', 
       ), 
      ), 
      'searchAnalyzer' => array(
       'type' => 'custom', 
       'tokenizer' => 'SQLedgeNGram', 
       'filter' => array(
        'lowercase', 
       ), 
      ) 
     ), 
     'tokenizer' => array(
      'SQLedgeNGram' => array(
       'type' => 'edgeNGram', 
       'min_gram' => 2, 
       'max_gram' => 35, 
       'side' => 'front' 
      ), 
      'standardNoStop' => array(
       'type' => 'standard', 
       'stopwords' => '' 
      ) 
     ) 
    ) 
), true 
); 

這裏是我的測試用例字段值:

Abbott and Costello - Funniest Routines, Vol. 

嘗試各種分析儀,我似乎無法得到它匹配任何包含「和「

結果:

searching [abbot] 
@  searchAnalyzer   total results: 1 
@  standard    total results: 1 
@  simple     total results: 1 
@  whitespace    total results: 1 
@  keyword     total results: 1 


searching [abbot ] 
@  searchAnalyzer   total results: 1 
@  standard    total results: 1 
@  simple     total results: 1 
@  whitespace    total results: 1 
@  keyword     total results: 1 


searching [abbot and c] 
    searchAnalyzer   total results: 0 
    standard    total results: 0 
    simple     total results: 0 
    whitespace    total results: 0 
    keyword     total results: 0 


searching [abbot and cost] 
    searchAnalyzer   total results: 0 
    standard    total results: 0 
    simple     total results: 0 
    whitespace    total results: 0 
    keyword     total results: 0 


searching [abbot and costello] 
    searchAnalyzer   total results: 0 
    standard    total results: 0 
    simple     total results: 0 
    whitespace    total results: 0 
    keyword     total results: 0 


searching [abbot costello] 
    searchAnalyzer   total results: 0 
    standard    total results: 0 
    simple     total results: 0 
    whitespace    total results: 0 
    keyword     total results: 0 

回答

1

您在查詢中有錯字(雅培缺少第二個T)。你也不需要通過ngram進行搜索。搜索標記器可以是關鍵字,它仍然適用於短於35個字符的短語。順便說一句,edgeNGram只會給你尾隨通配符。對於前導和尾隨通配符,您需要使用nGram濾鏡。

+0

我知道這是一個簡單的答案,但感謝您花時間指出問題,這使我很悲傷..檢查了一切,但最明顯的:( – Eva

相關問題