Skip to content

Improve matches for highlighting #691

Closed

Description

@simonduchen

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?

Activity

  1. github-actions commented on Jan 27, 2023

    @github-actions

    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

  2. krisk commented on May 14, 2026

    @krisk
    Owner

    Same underlying bug. Shipped a fix in v7.4.0-beta.6 (npm install fuse.js@beta), with a bonus ~15% perf win on includeMatches queries. Cross-linking from #792 where I posted the diagnosis and the residual behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions