【问题标题】:Elasticsearch phrase suggesterElasticsearch 短语建议器
【发布时间】:2014-04-09 14:05:09
【问题描述】:

我想使用“Phrase Suggester”。我有问题。输入“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'
                                    ),
                                )),
        )
);

引用值示例:

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

提前致谢。

【问题讨论】:

    标签: elasticsearch search-suggestion


    【解决方案1】:

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

    我可以向你推荐的是,使用“both”:

    1. 使用不带模糊的基本完成提示器进行搜索
    2. 使用词组建议搜索
    3. 使用模糊等循环到 (1) ......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 2017-10-23
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 2013-09-25
      相关资源
      最近更新 更多