Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Score is not working correctly #354

Closed
laurentiustroia opened this issue Mar 9, 2020 · 6 comments
Closed

Score is not working correctly #354

laurentiustroia opened this issue Mar 9, 2020 · 6 comments
Labels

Comments

@laurentiustroia
Copy link

Hi,

in last version 3.6.1 the score is not between 0 and 1. This can be check on https://fusejs.io/ too.

Example request + config:

  shouldSort: true,
  includeScore: true,
  threshold: 0,
  location: 0,
  distance: 0,
  maxPatternLength: 32,
  minMatchCharLength: 1,
  keys: [
    "title",
    "author.firstName"
  ]
};
var fuse = new Fuse(list, options); // "list" is the item array
var result = fuse.search("Old Man's War");

the output:

[
  {
    "item": {
      "title": "Old Man's War",
      "author": {
        "firstName": "John",
        "lastName": "Scalzi"
      }
    },
    "score": 2.220446049250313e-16
  }
]
@laurentiustroia
Copy link
Author

laurentiustroia commented Mar 9, 2020

Before last release this was 0 if exact match

@krisk
Copy link
Owner

krisk commented Mar 9, 2020

@laurentiustroia, 2.220446049250313e-16 evaluates to 0.0000000000000002220446049250313 😄 .

True that the previous release was an exact 0, but I've been making some modifications to increase perf. Nonetheless, I'm making some other adjustments that should make an exact match a score of 0. Bear with me.

In the meantime, is the score not being zero breaking some logic for you?

@krisk krisk added the question label Mar 9, 2020
@laurentiustroia
Copy link
Author

Me based on that score to know when is exact match, otherwise is good to update the docs to know exactly how i can see exact match vs a variation name, example, if search red in above array ["red", "redis"]

@MadsMadsDk
Copy link

I ran in to this issue as well. As a quick workaround, I applied .toFixed(2) to the score, so I was able to filter exact results from partial matches.

@connebs
Copy link

connebs commented Apr 16, 2020

Yeah, this broke my logic and took me a while to debug. The docs should definitely be changed if an exact match is no longer strict equality 0.

@MadsMadsDk I'm not sure that is the best way to do it, as partial match scores can be as low as 0.001, which with your fix would be cast as "perfect" even though it's not quite.

I've gone with this for the time being:

const perfectMatch = result.score < 1E-10;

But I think it would be very good to have a solution with a strong guarantee when a result is a perfect match.

@krisk
Copy link
Owner

krisk commented Apr 19, 2020

Addressed this in v5.2.2-alpha.0.

However, I'm undecided about this. I've started a discussion in #397.

[Will close this and use the above issue instead]

@krisk krisk closed this as completed Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants