我有一个名为 search_suggest 的字段,其内容如下
search_suggest: {
type: "completion",
analyzer: "simple",
payloads: true,
preserve_separators: false,
preserve_position_increments: false,
max_input_length: 50
}
它的值索引为
{
input: [
"apple iphone 6"
],
output: "apple iphone 6",
weight: 5,
payload: {
category: "mobiles"
}
}
如果我搜索 apple ,它会给我结果。但如果我搜索 iphone,它不会给我任何结果。
completion suggester 有什么办法可以做到这一点吗?。 我必须将输入索引为
- 苹果手机 6
- iPhone 6
- 6
我知道 edge-ngram suggester。但缺点是它也会提示重复项。
请帮忙。
最佳答案
如果有人还在寻找答案,
Completion suggester 适用于前缀匹配。因此,在输入中,您可以提供短语的可能后缀。这将允许您进行前缀搜索,即使您从中间开始,也就是子字符串搜索。
例如:
{
"text" : "Courtyard by Marriot Munich City",
"text_suggest" : {
"input": [
"Courtyard by Marriot Munich City",
"by Marriot Munich City",
"Marriot Munich City",
"Munich City",
"City"
],
"output" : "Courtyard by Marriot Munich City",
"weight" : 11,
"payload": { "id" : 314159 }
}
}
如您所见,无论您从“慕尼黑市万怡酒店”开始,您都会得到结果。 (除了可能用于“by”,因为在大多数情况下它将被丢弃为停用词)。
对于一般搜索字符串,最多 4-5 个步骤就足够了。此外,如果您使用过滤器处理停用词,则无需担心输入中的停用词。
样本索引分析器
{
"settings" : {
"analysis" : {
"filter" : {
"suggester_stop" : {
"type" : "stop",
"stopwords" : "_english_",
"remove_trailing" : false,
"ignore_case" : true
},
"suggester_stemmer" : {
"type" : "stemmer",
"name" : "light_english"
}
},
"analyzer" : {
"suggester_analyzer" : {
"type" : "custom",
"tokenizer" : "standard",
"char_filter" : ["html_strip"],
"filter" : [
"standard",
"lowercase",
"suggester_stop",
"suggester_stemmer"
]
}
}
}
}
}
这将解决您在其中一条评论中提到的问题:
Then if I suggest for "apple ip", It won't give result. How about iphone 6?
{
"text_suggest" : {
"input": [
"apple iphone 6",
"iphone 6"
],
"output" : "apple iphone 6",
"weight" : 11
}
}
您将获得“apple ip”、“iphone 6”等的搜索结果。但是您不会获得“apple 6”的结果,这对于人们搜索来说并不常见。
关于php - 完成建议elasticsearch中从中间部分匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38178565/