我使用Fuse.js来实现一个搜索系统来解决我的不和谐的机器人。但是,当我给出搜索字符串“纸美人(觉醒)”时,它会返回另一个与其类似的项,作为数组中的第一个元素。
结果:
[
{
item: 'Paper Beauty (Winter)',
refIndex: 77,
score: 0.01857804455091699
},
{
item: 'Paper Beauty (Awakened)',
refIndex: 135,
score: 0.01857804455091699
},
{ item: 'Patternine', refIndex: 122, score: 0.4 },
{ item: 'Bright Reaper', refIndex: 31, score: 0.40657505381748826 },
{ item: 'Spade', refIndex: 112, score: 0.41000000000000003 },
{ item: 'Puppet', refIndex: 61, score: 0.42000000000000004 },
{ item: 'Expert Sorcerer', refIndex: 8, score: 0.5231863610884103 },
{ item: 'Water Goddess', refIndex: 13, score: 0.5231863610884103 },
{ item: 'Water Bender', refIndex: 41, score: 0.5231863610884103 },
{ item: 'Super Firework', refIndex: 176, score: 0.5231863610884103 },
{ item: 'Spider Boss', refIndex: 44, score: 0.5324001715007329 }
]代码:
const Fuse = require("fuse.js");
const { trendSystem, demandSystem } = require("../../util/functions");
const names = require("../../names.json");
module.exports = {
name: "stats",
category: "trading",
devOnly: false,
run: async ({ client, message, args }) => {
const options = {
includeScore: true,
};
const searcher = new Fuse(names, options);
const results = searcher.search(args[0]).slice(0, 11)
console.log(results)
}
}发布于 2022-06-23 03:44:02
评分是根据三个因素进行的:
#距离、阈值和位置--对要被视为匹配的事物的计算(无论是模糊的还是精确的)考虑到模式与预期位置之间的距离,在阈值内。
为了举例说明,请考虑以下选项:
100
有了上述选项,要想将某些内容视为匹配,则必须在(阈值)0.6x(距离) 100 =60个字符内才能达到预期位置0。
在你的例子中,这种情况也可能发生:
例如,考虑字符串"Fuse.js是一个功能强大的轻量级模糊搜索库,具有零依赖项“。搜索模式“零”将不匹配任何东西,即使它发生在字符串中。原因是,对于上述默认值,如果要将其视为匹配,则必须在距离预期位置0的60个字符内。然而,“零”出现在指数62。
注意:您需要调整配置以获得正确的结果。
https://stackoverflow.com/questions/72723149
复制相似问题