这是我在 elasticSearch 上的字段:
"keywordName": {
"type": "text",
"analyzer": "custom_stop"
}
这是我的分析器:
"custom_stop": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"my_stop",
"my_snow",
"asciifolding"
]
}
这是我的过滤器:
"my_stop": {
"type": "stop",
"stopwords": "_french_"
},
"my_snow" : {
"type" : "snowball",
"language" : "French"
}
这是我的文档我的索引(在我唯一的字段中:keywordName):
“canne a peche”、“canne”、“canne a peche telescopique”、“iphone 8”、“iphone 8 手机壳”、“iphone 8 保护套”、“iphone 8 充电器”、“iphone 8 new”
当我搜索“canne”时,它给了我“canne”文档,这就是我想要的:
GET ads/_search
{
"query": {
"match": {
"keywordName": {
"query": "canne",
"operator": "and"
}
}
},
"size": 1
}
当我搜索“canne à pêche”时,它会给我“canne a peche”,这也可以。“Cannes à Pêche” -> “canne a peche” -> 好。
这是棘手的部分:当我搜索“iphone 8”时,它给了我“iphone 8 cover”而不是“iphone 8”。如果我更改大小,我设置 5(因为它返回包含“iphone 8”的 5 个结果)。我看到“iphone 8”是得分的第四个结果。首先是“iphone 8 cover”,然后是“iphone 8 case”,然后是“iphone 8 new”,最后是“iphone 8”......
这是查询的结果:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1.4009607,
"hits": [
{
"_index": "ads",
"_type": "keyword",
"_id": "iphone 8 cover",
"_score": 1.4009607,
"_source": {
"keywordName": "iphone 8 cover"
}
},
{
"_index": "ads",
"_type": "keyword",
"_id": "iphone 8 case",
"_score": 1.4009607,
"_source": {
"keywordName": "iphone 8 case"
}
},
{
"_index": "ads",
"_type": "keyword",
"_id": "iphone 8 new",
"_score": 0.70293105,
"_source": {
"keywordName": "iphone 8 new"
}
},
{
"_index": "ads",
"_type": "keyword",
"_id": "iphone 8",
"_score": 0.5804671,
"_source": {
"keywordName": "iphone 8"
}
},
{
"_index": "ads",
"_type": "keyword",
"_id": "iphone 8 charge",
"_score": 0.46705723,
"_source": {
"keywordName": "iphone 8 charge"
}
}
]
}
}
我怎样才能保持关键字“canne a peche”(重音、大写字母、复数)的灵活性,但也告诉他如果有完全匹配(“iphone 8”=“iphone 8”),给我确切的关键字名称?