Fuse.js exact search and fuzzy search not working correct when searchedText has more length

284 Views Asked by At

I was trying Fuse.js for searching in react.js web application. I need to have exact search when exact value is searched and fuzzy search when no exact value present.

const data = [{"title": "Test-One-123-E99384384384384HSNNS8789"},{"title": "Test-One-123-E99384384384384HSNNS8786"},{"title": "Test-One-123-E99384384384384HSNNS8784"}];

const keys = ["title"];

const fuseOptions = {
keys,
threshold:0.5,
includeScore: true,
ignoreLocation: true,
distance:100
}

const dataFuse = new Fuse(data, fuseOptions);
const items = query ? dataFuse.search(query).map(({item}) => item) : data;

If I search "Test-One-123-E99384384384384HSNNS8789" I should only get 1 object but in this case I am getting all 3 objects. This code is working fine if the title length is less. Its failing only when title is longer.

Anyone know anything about this?

1

There are 1 best solutions below

0
Hans Knöchel On

You likely get all results because of the partial matches of the substring E99384384384384HSNNS878. You can sort the results by the score which should already provide the highest ranking for your expected item.