Fuzzy matching not working for typos
Is there an existing issue for this?
- [X] I have searched the existing issues
Description of the bug
My use case is to extract color names from a given string. And I have provided the list of color names as my collection. But when I try to get the closest match for a color name with a typo, the fuse does not match with any of them, even when it's a single-character typo.
For example: Collection = ["Red", "Green", "Black"] Search word = "grean" Result from fuse = []
I wanted to know why this is not working. And did anyone face this kind of issue earlier?
The Fuse.js version where this bug is happening.
6.6.2
Is this a regression?
- [ ] This is a regression bug
Which version did this behavior use to work in?
Steps To Reproduce
Here is the fiddle link to check: https://jsfiddle.net/ykecbuaz/12/ Open the fiddle console and try "grean" in the search bar.
Fuse options I used:
const fuseOptions = {
isCaseSensitive: false,
includeScore: true,
minMatchCharLength: 1,
shouldSort: true,
findAllMatches: false,
location: 0,
threshold: 0.1,
distance: 10,
// ignoreLocation: true,
// useExtendedSearch: false,
// ignoreFieldNorm: false,
// fieldNormWeight: 1,
};
Expected behavior
Typo words should match the nearest similar word. For example: "grean" should match "green".
Screenshots
No response
Additional context
No response
Also, one point I want to highlight. If I reduce the threshold to 0.4, then it will return "green" for "grean" query.
But now the issue with this threshold is it will return unrelated matches as well, for example, for "pen" we get "pink" which is completely unrelated.
if you have an array of strings as your haystack and want simple typo tolerance, you can try uFuzzy (with intraMode: 1)
@leeoniya thanks for the suggestion will check this out.