Elasticsearch短语建议者

时间:2014-04-09 14:05:10

标签: elasticsearch search-suggestion

我想使用“Phrase Suggester”。我有一个问题。输入“johni depp”时, 它按此顺序返回几个结果:

  1. john depp
  2. johnny depp
  3. joann depp
  4. johnn depp
  5. 如何使用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": []
    }
    

    Indexer(我使用Elastica,但它是一样的):

    $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'
                                        ),
                                    )),
            )
    );
    

    参考值的示例:

    • John Cleese
    • John Gemberling
    • Johnny Hallyday
    • Johnny Depp
    • Joann Sfar
    • Joanna Rytel
    • Samuel Johnson
    • JohnsonTraoré

    提前致谢。

1 个答案:

答案 0 :(得分:0)

看起来你想要"完成建议者"代替?

我可以推荐你,使用"两者":

  1. 使用基本完成建议器搜索w / o fuzzy
  2. 使用短语建议器搜索
  3. 使用模糊等循环到(1)....