首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Fuse.js错误记分系统

Fuse.js错误记分系统
EN

Stack Overflow用户
提问于 2022-06-22 23:58:32
回答 1查看 266关注 0票数 0

我使用Fuse.js来实现一个搜索系统来解决我的不和谐的机器人。但是,当我给出搜索字符串“纸美人(觉醒)”时,它会返回另一个与其类似的项,作为数组中的第一个元素。

结果:

代码语言:javascript
复制
[
  {
    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 }     
]

代码:

代码语言:javascript
复制
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)
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-06-23 03:44:02

评分是根据三个因素进行的:

  1. 模糊评分
  2. 关键规范

#距离、阈值和位置--对要被视为匹配的事物的计算(无论是模糊的还是精确的)考虑到模式与预期位置之间的距离,在阈值内。

为了举例说明,请考虑以下选项:

100

  • threshold默认的
  • 位置为0
  • 距离默认为0.6

有了上述选项,要想将某些内容视为匹配,则必须在(阈值)0.6x(距离) 100 =60个字符内才能达到预期位置0。

在你的例子中,这种情况也可能发生:

例如,考虑字符串"Fuse.js是一个功能强大的轻量级模糊搜索库,具有零依赖项“。搜索模式“零”将不匹配任何东西,即使它发生在字符串中。原因是,对于上述默认值,如果要将其视为匹配,则必须在距离预期位置0的60个字符内。然而,“零”出现在指数62。

注意:您需要调整配置以获得正确的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72723149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档