krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.76k stars 753 forks source link

Fuzzy matching not working for typos #759

Open dhyeythumar opened 4 months ago

dhyeythumar commented 4 months ago

Is there an existing issue for this?

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?

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

dhyeythumar commented 4 months ago

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.

leeoniya commented 4 months ago

if you have an array of strings as your haystack and want simple typo tolerance, you can try uFuzzy (with intraMode: 1)

dhyeythumar commented 4 months ago

@leeoniya thanks for the suggestion will check this out.

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days