krisk / Fuse

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

Improve matches for highlighting #691

Closed simonduchen closed 1 year ago

simonduchen commented 2 years ago

Hello, In the example below, fuse is used to filter a table and all matches are highlighted. We search for "consequat" and there are matches all over the text. Even though there is an exact match there is a lot of other quite far fetched matches that are highlighted as well. image These are the options set:

 const options = {
    includeMatches: true,
    threshold: 0.2,
    ignoreLocation: true,
    minMatchCharLength: 2,
};

Using the matches included in the search result does therefore not work that well for highlighting as it can include matches for every other letter in a text even though there is an exact match as in the example above, and to set the threshold lower won´t affect it much or at all. Correct me if I am wrong but it doesn´t seem that the matches are affected by the set threshold?

This is brought up in this discussion ticket as well. As one of the comments mention in that ticket, there is a possible solution by filtering the matches and only highlight and "best" ones.

The above mentioned issue is easier seen in longer texts but it is present in other cases as well, like this example: image As we have an exact match the other matches are only disturbing and creates visual excise.

However, is this something that can be improved or is it purposely designed like this? Maybe the root cause of this behavior is the core search algorithm used in fuse?

github-actions[bot] commented 1 year 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