gpt4 book ai didi

django - 如何检索触发Elasticsearch查询命中的字段

转载 作者:行者123 更新时间:2023-12-03 01:43:36 25 4
gpt4 key购买 nike

使用Elasticsearch(5.5)作为搜索后端运行wagtail网站(1.11),并为多个字段建立索引,例如:

search_fields = Page.search_fields + [
index.SearchField('body'),
index.SearchField('get_post_type_display'),
index.SearchField('document_excerpt', boost=2),
index.SearchField('get_dark_data_full_text'),
]

我想指出搜索在我的搜索结果模板中的哪个字段中找到了“匹配项”(甚至更好地显示了该匹配项的摘要,但这似乎是另一个问题)。

This question似乎解决了我的问题,但是我不知道如何将其集成到我的wagtail网站中。

关于如何获取此信息以及如何将它们整合到integrate搜索中的任何提示?

最佳答案

ElasticSearch具有Explain API,该API可以解释它如何在内部为具有特定ID的特定记录按字段对命中得分。

这里是文档:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html

它肯定会为您提供有关如何提高每个 Realm 以及如何建立分数的答案。

例如,如果您的命中率max_score为2.0588222,并且您想知道哪些字段对这一得分有贡献,则可以使用explain API。

这是一个解释查询响应的示例,在该示例中,您看到字段firstName为最大得分贡献了1.2321436,而lastName为0.8266786贡献了:

{
"_index" : "customer_test",
"_type" : "customer",
"_id" : "597f2b3a79c404fafefcd46e",
"matched" : true,
"explanation" : {
"value" : **2.0588222**,
"description" : "sum of:",
"details" : [ {
"value" : 2.0588222,
"description" : "sum of:",
"details" : [ {
"value" : **1.2321436**,
"description" : "weight(firstName:merge in 23) [PerFieldSimilarity], result of:",
"details" : [ {
"value" : 1.2321436,
"description" : "score(doc=23,freq=1.0 = termFreq=1.0\n), product of:",
"details" : [ {
"value" : 1.2321436,
"description" : "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details" : [ {
"value" : 3.0,
"description" : "docFreq",
"details" : [ ]
}, {
"value" : 11.0,
"description" : "docCount",
"details" : [ ]
} ]
}, {
"value" : 1.0,
"description" : "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details" : [ {
"value" : 1.0,
"description" : "termFreq=1.0",
"details" : [ ]
}, {
"value" : 1.2,
"description" : "parameter k1",
"details" : [ ]
}, {
"value" : 0.75,
"description" : "parameter b",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "avgFieldLength",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "fieldLength",
"details" : [ ]
} ]
} ]
} ]
}, {
"value" : 0.8266786,
"description" : "weight(lastName:doe in 23) [PerFieldSimilarity], result of:",
"details" : [ {
"value" : 0.8266786,
"description" : "score(doc=23,freq=1.0 = termFreq=1.0\n), product of:",
"details" : [ {
"value" : **0.8266786**,
"description" : "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details" : [ {
"value" : 3.0,
"description" : "docFreq",
"details" : [ ]
}, {
"value" : 7.0,
"description" : "docCount",
"details" : [ ]
} ]
}, {
"value" : 1.0,
"description" : "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details" : [ {
"value" : 1.0,
"description" : "termFreq=1.0",
"details" : [ ]
}, {
"value" : 1.2,
"description" : "parameter k1",
"details" : [ ]
}, {
"value" : 0.75,
"description" : "parameter b",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "avgFieldLength",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "fieldLength",
"details" : [ ]
} ]
} ]
} ]
} ]
}, {
"value" : 0.0,
"description" : "match on required clause, product of:",
"details" : [ {
"value" : 0.0,
"description" : "# clause",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "_type:customer, product of:",
"details" : [ {
"value" : 1.0,
"description" : "boost",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "queryNorm",
"details" : [ ]
} ]
} ]
} ]
}
}

关于w:我没有经验。但是您绝对可以访问REST API并解析Explain查询的JSON。

关于django - 如何检索触发Elasticsearch查询命中的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45690314/

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