0

我想使用“短语建议”。我有问题。键入“johni depp”时,它会按以下顺序返回几个结果:

  1. 约翰德普
  2. 约翰尼·德普
  3. 琼德普
  4. 约翰德普

如何使用 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": []
}

索引器(我使用 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'
                                    ),
                                )),
        )
);

参考值示例:

  • 约翰·克莱斯
  • 约翰·金伯林
  • 约翰尼·哈利戴
  • 约翰尼·德普
  • 乔安·斯法尔
  • 乔安娜瑞特尔
  • 塞缪尔·约翰逊
  • 约翰逊·特拉奥雷

提前致谢。

4

1 回答 1

0

看起来您想要“完成建议”?

我可以向您推荐的是,使用“两者”:

  1. 使用无模糊的基本完成建议器进行搜索
  2. 使用词组建议器进行搜索
  3. 用模糊等循环到(1)......
于 2014-08-21T08:26:38.163 回答