I want to implement a fuzzy search. I use fuse.js for this.
The problem is, when I search for banking, for example, all other terms with B are also displayed.
I have the following data structure:
const data = [
{
letter: "A",
items: [
{
title: "Authentification",
},
],
},
{
letter: "B",
items: [
{
title: "Banking",
},
{
title: "Banana",
},
{
title: "Basketball",
},
],
},
];
This is my code:
onChange={async (e) => {
const { value } = e.currentTarget;
const Fuse = (await import("fuse.js/min")).default;
const fuse = new Fuse(formattedGlossar || [], {
keys: ["items.title"],
distance: 0.7,
});
value === ""
? setItems(formattedGlossar)
: setItems(fuse.search(value).map((item) => item.item));
}}
This is the result I get from the search, when i search for “Banking”:
[
{
"item": {
"letter": "B",
"items": [
{
"title": "Banking",
},
{
"title": "Banana",
},
{
"title": "Basketball",
}
]
},
"refIndex": 1,
"score": 2.220446049250313e-16
}
]
I don’t know what I’m doing wrong, because I’ve followed the documentation exactly.
https://www.fusejs.io/examples.html#nested-search