gpt4 book ai didi

search - 更喜欢在搜索结果的开头而不是在结尾使用 elasticsearch 匹配搜索词

转载 作者:行者123 更新时间:2023-11-29 02:57:13 24 4
gpt4 key购买 nike

我有一个查询,但我无法返回最相关的答案。

如果我搜索“herp”,结果是

  • 福赫普
  • 草草
  • 条状疱疹
  • 疱疹病毒

最好我想要这个顺序

  • 疱疹病毒
  • 草草
  • 条状疱疹
  • 福赫普

所以我想我的问题是:如何让位于一系列单词开头的词项比出现在结尾处的词项得分更高?

我使用的分析器是这样的:

"analyzer":[
"autocomplete":[
"type":"custom",
"tokenizer":"standard",
"filter":[
"standard",
"lowercase",
"stop",
"edgeNGramAlpha"
]
],
"filter":[
"edgeNGramAlpha":[
"type":"edgeNGram",
"min_gram":1,
"max_gram":20
]
]
]

并且映射看起来像这样(战利品田地但阿拉看起来一样)

"name": [
"type": "multi_field",
"fields" : [
"untouched": [
"type": "string",
"index": "not_analyzed"
],
"name": [
"type": "string"
],
"autocomplete": [
"analyzer":"${language}_autocomplete",
"type":"string",
]
]
]

查询看起来像这样:

{
"from": 0,
"size": 10,
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "herp",
"fields": [
"name^8",
"name.autocomplete^4",
"historic_name.autocomplete"
],
"type": "cross_fields",
"operator": "AND",
"analyzer": "standard"
}
}
}
}
}

最佳答案

实现此目的的一种方法是在字段开头使用 span first 为术语提供额外的提升。

示例:

{
"from": 0,
"size": 10,
"query": {
"bool": {
"disable_coord": true,
"must": [
{
"multi_match": {
"query": "herp",
"fields": [
"name^8",
"name.autocomplete^4",
"historic_name.autocomplete"
],
"analyzer": "standard"
}
}
],
"should": [
{
"span_first": {
"match": {
"span_term": {
"name": "herp"
}
},
"end": 1,
"boost": 1
}
},
{
"span_first": {
"match": {
"span_term": {
"historic_name": "herp"
}
},
"end": 1,
"boost": 1
}
}
],
"minimum_number_should_match": 0
}
}
}

关于search - 更喜欢在搜索结果的开头而不是在结尾使用 elasticsearch 匹配搜索词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25569630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com