I used Fuse.js to implement a search system to my discord bot. However when I give the search string “Paper Beauty (Awakened)”, It returns another Item that is similar to it as the first element in the array.
Results:
[
{
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 }
]
Code:
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)
}
}