krisk / Fuse

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

Obvious exact match missing from results #404

Closed wbobeirne closed 4 years ago

wbobeirne commented 4 years ago

Describe the bug

I was testing out my search implementation, and it was mostly going well until I tried using a specific keyword (in my example case, it was "SAML".) Despite being an exact match in many items in the array, I get no results. Perhaps I'm missing some key configuration, or I'm severely misunderstanding the way Fuse works, but my expectation is that this would be a slam dunk for a search result match.

Version

5.1.0

🔬Minimal Reproduction

On the live demo page, this is reproducible with the following:

list.json

[
  {
    "heading": "Update",
    "text": "The Users page provides many options for adjusting a user, such as SAML"
  }
 ]

main.js

const options = {
  isCaseSensitive: false,
  includeMatches: true,
  keys: [
    "heading",
    "text"
  ]
};

const fuse = new Fuse(list, options);

// Change the pattern
const pattern = "SAML"

return fuse.search(pattern)
krisk commented 4 years ago

Working as expected.

The reason it's not matching is due to the combination of location, distance & threshold.

Specifically:

The calculation for it be considered a match (whether fuzzy or exact) takes into account how far the pattern is from the expected location, with a threshold calculation (see here)

With the above defaults, for it to be considered a match it would have to be within (threshold) 0.6 x (distance) 100 = 60 characters away from the expected location.

However, in your case, "SAML" appears at index 67.

To address, you can either change distance to a larger number, or change the threshold. I would recommend the former.

Separately, I'm working on ways to exclude distance & location from the calculation, so that people don't have to worry about fiddling with these options.

wbobeirne commented 4 years ago

Gotcha, thanks for the explanation. I'm thinking fuzzy search may be overkill for my case, and I should just tackle my problem with a more naive search.