question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should-be perfect match has non-zero score

See original GitHub issue

Describe the bug

When searching for a keyword in a list of objects, the search works and finds matches. However, the should-be perfect matches return a non-zero score like 2.220446049250313e-16. This should be 0 as it is a perfect match, but due to not being exactly 0, it continues the search.

The Minimal Production below gives this as its result:

0: {item: {…}, refIndex: 0, matches: Array(1), score: 2.220446049250313e-16}
1: {item: {…}, refIndex: 1, matches: Array(1), score: 0.2}
2: {item: {…}, refIndex: 2, matches: Array(1), score: 0.2}
3: {item: {…}, refIndex: 3, matches: Array(1), score: 0.2}
4: {item: {…}, refIndex: 4, matches: Array(1), score: 0.2}

Version

6.4.1

Is this a regression?

Yes, the previous version in which this bug was not present was: 3.6.1 (Im using it in another project, there it works fine)

🔬Minimal Reproduction

  const items = [
    {
      value : 'test1',
    },
    {
      value : 'test2',
    },
    {
      value : 'test3',
    },
    {
      value : 'test4',
    },
    {
      value : 'test5',
    },
  ];

  const fuse = new Fuse(items, {
    ignoreLocation : true,
    includeMatches : true,
    includeScore   : true,
    keys           : ['value'],
  });

  console.log(fuse.search('test1'));

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
Emronicommented, Sep 13, 2020
fuse.search('test2').forEach((it) => it.score = Number(it.score.toFixed(2)));

I’ve used that workaround too, although I would recommend using Math.round((score * 100) / 100) as its much slower to use toFixed() and then casting to `Number. Especially if there are thousands of records, it would slow it down significantly.

0reactions
smasalacommented, Oct 14, 2020

Bump

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lecture 12 1 Review 2 Perfect Matching
such a matching is perfect if every vertex has exactly one edge incident on it. ... permutations will also yield a non-zero result....
Read more >
When to stop dating and settle down, according to math
The magic figure turns out to be 37 percent. To have the highest chance of picking the very best suitor, you should date...
Read more >
Lecture 1: Perfect Matching Testing via Matrix Determinant 1 ...
It follows that det(B) ∕= 0. This suggests the following algorithm to determine whether G has a perfect matching.
Read more >
Perfect Matching -- from Wolfram MathWorld
A perfect matching of a graph is a matching (i.e., an independent edge set) in which every vertex of the graph is incident...
Read more >
Perfect game (baseball) - Wikipedia
To achieve a perfect game, a team must not allow any opposing player to reach base by any means: no hits, walks, hit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found