Here is the example code of Fuse.js:
import Fuse from "https://deno.land/x/fuse/dist/fuse.esm.js";
const list = [
{
"title": "Old Man's War",
"author": "John Scalzi",
"tags": ["fiction"]
},
{
"title": "The Lock Artist",
"author": "Steve",
"tags": ["thriller"]
}
]
const options = {
includeScore: true
}
const fuse = new Fuse(list, options)
const result = fuse.search('od man')
console.log("🚀 ~ fuse:", fuse)
console.log("🚀 ~ result:", result)
The result is just []. Do you know why is that?
>Solution :
You’ve not configured the keys:
const options = {
includeScore: true,
keys: ['title', 'author'],
};
will give you result:
[
{
item: { title: "Old Man's War", author: 'John Scalzi', tags: [Array] },
refIndex: 0,
score: 0.3556368284111493
}
]