gpt4 book ai didi

node.js - Node JS Elasticsearch 结果改进

转载 作者:行者123 更新时间:2023-12-03 02:18:26 24 4
gpt4 key购买 nike

使用与累计相关的 Elasticsearch 时出现问题,
示例数据

{
"id": 2,
"keyword": "Gas",
"content": "{\"detail_name\":\"Gas\",\"detail_slug\":\"gas\",\"category_name\":\"Cooking\",\"category_slug\":\"cooking\",\"subcategory_name\":\"Cooktops\",\"subcategory_slug\":\"cooktops\",\"type\":\"1\"}"
},
{
"id": 4,
"keyword": "Gas: Downdraft",
"content": "{\"detail_name\":\"Gas: Downdraft\",\"detail_slug\":\"gas-downdraft\",\"category_name\":\"Cooking\",\"category_slug\":\"cooking\",\"subcategory_name\":\"Cooktops\",\"subcategory_slug\":\"cooktops\",\"type\":\"1\"}"
},
{
"id": 86,
"keyword": "Casement / Slider A / C Air Conditioner",
"content": "{\"detail_name\":\"Casement \/ Slider A \/ C Air Conditioner\",\"detail_slug\":\"casement-slider-a-c-air-conditioner\",\"category_name\":\"Air Conditioning\",\"category_slug\":\"air-conditioning\",\"subcategory_name\":\"Air Conditioners\",\"subcategory_slug\":\"air-conditioners\",\"type\":\"1\"}"
},
{
"id": 91,
"keyword": "0 - 30 Pint Dehumidifier",
"content": "{\"detail_name\":\"0 - 30 Pint Dehumidifier\",\"detail_slug\":\"0-30-pint-dehumidifier\",\"category_name\":\"Air Conditioning\",\"category_slug\":\"air-conditioning\",\"subcategory_name\":\"Dehumidifiers\",\"subcategory_slug\":\"dehumidifiers\",\"type\":\"1\"}"
}
这是我的代码
client.search({
index: 'search_index',
size: 4,
body: {
sort: [{ "id": { "order": "asc" } }],
query: {
fuzzy: {
keyword: {
value: req.query.q,
"fuzziness": "1",
"max_expansions": 50,
"prefix_length": 0,
// "rewrite": "constant_score"
}
}
}
}
}, (err, result) => {})
因此,当我输入关键字“g”或“Downdraft Gas”时,我想显示“Gas”或“Gas:Downdraft”
有没有我需要进一步改进的代码?
谢谢

最佳答案

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
这些确实帮助我改善了搜索查询。
永远不要使用模糊
在这种情况下,模糊查询将无济于事。文档引用:“返回包含与搜索词相似的词的文档,以Levenshtein编辑距离来衡量。编辑距离是将一个词转换为另一个词所需的一个字符更改的数量。”因此,如果您搜索“模糊度为1的“gas”会得到“has”,“gap”等结果。

关于node.js - Node JS Elasticsearch 结果改进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63050557/

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