【发布时间】:2014-04-09 14:05:09
【问题描述】:
我想使用“Phrase Suggester”。我有问题。输入“johni depp”时, 它按此顺序返回几个结果:
- 约翰·德普
- 约翰尼·德普
- 乔安·德普
- 约翰·德普
如何使用 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