Skip to content

includeMatches includes unexpected matches #505

Closed

Description

@hadley

Describe the bug

On the live demo page, I use the following code:

const options = {
  // isCaseSensitive: false,
  // includeScore: false,
  // shouldSort: true,
  includeMatches: true,
  // findAllMatches: false,
  // minMatchCharLength: 1,
  // location: 0,
  threshold: 0.1,
  // distance: 100,
  // useExtendedSearch: false,
  // ignoreLocation: false,
  // ignoreFieldNorm: false,
  keys: [
    "title",
    "author.firstName"
  ]
};

const fuse = new Fuse(list, options);

// Change the pattern
const pattern = "war"

return fuse.search(pattern)

and it returns two results:

[
  {
    "item": {
      "title": "Backwards, Red Dwarf",
      "author": {
        "firstName": "Rob",
        "lastName": "Grant"
      }
    },
    "refIndex": 17,
    "matches": [
      {
        "indices": [
          [1, 1],
          [4, 6],
          [16, 18]
        ],
        "value": "Backwards, Red Dwarf",
        "key": "title"
      }
    ]
  },
  {
    "item": {
      "title": "Old Man's War",
      "author": {
        "firstName": "John",
        "lastName": "Scalzi"
      }
    },
    "refIndex": 0,
    "matches": [
      {
        "indices": [
          [5, 5],
          [10, 12]
        ],
        "value": "Old Man's War",
        "key": "title"
      }
    ]
  }
]

The matches appear to include text that doesn't match. E.g. the first match includes indices [1, 1], i.e. "a".

Version

6.4.2

Activity

  1. krisk commented on Oct 30, 2020

    @krisk
    Owner

    "a" is indeed matching (since the pattern is "war"). One way to omit single character matches is to set minMatchCharLength to a value > 1.

  2. hadley commented on Oct 30, 2020

    @hadley
    Author

    In that case, this is probably a duplicate of #504, because it surprises me that the match can be shorter than the search term.

  3. hadley commented on Oct 30, 2020

    @hadley
    Author

    Thinking about this more, I think I generally want a prefix match — i.e. if the use has typed "war", I want to match "war", "warfare", "warlord", but not "award", and not "a". This isn't quite ^war because I'd still like some fuzziness , and I want to apply it automatically to searches (although I guess I could just turn on extended search and paste "^" to the front of the search string).

  4. github-actions commented on Nov 30, 2020

    @github-actions

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

  5. 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

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions