2014-04-09 47 views
0

我想使用「Phrase Suggester」。我有一個問題。當輸入 「johni德普」, 返回順序幾個結果:Elasticsearch詞組建議者

  1. 約翰·德普
  2. 約翰尼·德普
  3. 喬安·德普
  4. johnn德普

我如何排序使用json的建議,以便第一個結果是「johnny depp」? 我試過用拼音索引器這樣做,但沒有成功。

這是我的配置:

查詢:

{ 
    "query": { 
    "multi_match": { 
     "query": "johni depp", 
     "fields": [ 
     "fullName.word" 
     ], 
     "operator": "and" 
    } 
    }, 
    "suggest": { 
    "text": "johni depp", 
    "film": { 
     "phrase": { 
     "analyzer": "whitespace-fullName", 
     "field": "fullName.whitespace", 
     "size": 5, 
     "real_word_error_likelihood": 0.95, 
     "max_errors": 0.5, 
     "gram_size": 2 
     } 
    } 
    }, 
    "from": 0, 
    "size": 1, 
    "sort": [], 
    "facets": [] 
} 

索引(我用的彈性曲線,但它是一回事):

$elasticaIndex->create(
       array(
        'number_of_shards' => 4, 
        'number_of_replicas' => 1, 
        'analysis'   => array(
         'analyzer' => array(
          'autocomplete-index-fullName' => array(
           'tokenizer' => 'standard', 
           'filter' => 'asciifolding, lowercase, edgeNGram' 
         ), 
          'autocomplete-search-fullName' => array(
           'tokenizer' => 'standard', 
           'filter' => 'asciifolding, lowercase' 
         ), 
          'word-fullName'    => array(
           'tokenizer' => 'keyword', 
           'filter' => 'lowercase' 
         ), 
          'whitespace-fullName'   => array(
           'tokenizer' => 'whitespace', 
           'filter' => 'lowercase' 
         ), 
        ), 
         'filter' => array(
          'edgeNGram' => array(
           'type'  => 'edgeNGram', 
           'min_gram' => 1, 
           'max_gram' => 15 
         ) 
        ) 
       ) 
      ), 
       false 
); 

映射:

$mapping->setProperties(
     array(
      'fullName' => array('type' => 'string', 
           'fields' => array(
            'autocomplete' => array(
             'type'   => 'string', 
             'index_analyzer' => 'autocomplete-index-fullName', 
             'search_analyzer' => 'autocomplete-search-fullName' 
            ), 
            'word'   => array(
             'type'   => 'string', 
             'analyzer' => 'word-fullName' 
            ), 
            'whitespace' => array(
             'type'   => 'string', 
             'analyzer' => 'whitespace-fullName' 
            ), 
           )), 
     ) 
); 

r。的例子eferenced值:

  • 約翰克里斯
  • 約翰·高伯林
  • 約翰尼·哈里代
  • 約翰尼·德普
  • 喬安·斯法
  • 喬安娜Rytel
  • 塞繆爾·約翰遜
  • 約翰遜特拉奧雷

在此先感謝。

回答

0

看起來像你想要「完成建議者」,而不是?

我可以推薦你,這是用「兩」:

  1. 搜尋基本完成建議者的w/o模糊
  2. 搜索與短語建議者
  3. 環路(1)用模糊等...