krisk / Fuse

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

All indices return with threshold = 0 aren't a perfect match #762

Open dbismut opened 3 months ago

dbismut commented 3 months ago

Is there an existing issue for this?

Description of the bug

Version 7.0 (but reproductible in 6.6.2)

It seems like when using a threshold of 0 combined with ignoreLocation to return a perfect match, as long as there is one perfect match in the searched text, all other groups of matches are returned no matter how fuzzy they are.

JSFiddle: https://jsfiddle.net/dp4efm2s/12/

The Fuse.js version where this bug is happening.

7.0.0

Which version did this behavior use to work in?

Not sure

Steps To Reproduce

const list = [
{ title: 'rouge desert groue'},
]

const fuseOptions = {
  //isCaseSensitive: false,
  includeScore: true,
  shouldSort: false,
  includeMatches: true,
  findAllMatches: false,
  minMatchCharLength: 2,
  threshold: 0,
  ignoreLocation: true,
  keys: ["title"]
};

const fuse = new Fuse(list, fuseOptions);

// Change the pattern
const searchPattern = "rouge"

console.log(fuse.search(searchPattern))

Here is the returned object:

[{
  item: {
    title: "rouge desert groue"
  },
  matches: [{
  indices: [[0, 4], [9, 10], [13, 17]],
  key: "title",
  value: "rouge desert groue"
}],
  refIndex: 0,
  score: 0.01857804455091699
}]

Expected behavior

There is only one perfect matching indice — which is the first one — so only one indice should be returned:

[{
  item: {
    title: "rouge desert groue"
  },
  matches: [{
  indices: [[0, 4]], // only ONE indice should be returned
  key: "title",
  value: "rouge desert groue"
}],
  refIndex: 0,
  score: 0.01857804455091699
}]

Screenshots

No response

Additional context

No response