krisk / Fuse

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

Exact matches on arrays of objects result in score higher than 1 #756

Closed erquhart closed 4 days ago

erquhart commented 5 months ago

Is there an existing issue for this?

Description of the bug

Matching an entire field exactly results in a seemingly random number, with a very complex decimal, typically somewhere between 1 and 8.

This is not specific to different configurations, it happens just using the defaults.

I've tried versions back to 5.2.1 and the behavior is the same.

The Fuse.js version where this bug is happening.

7.0.0

Note: the issue template only goes up to 6.6.2, had to edit this after creating.

Is this a regression?

Which version did this behavior use to work in?

None

Steps To Reproduce

const fuse = new Fuse([{ name: 'foo' }], { includeScore: true, keys: ['name'] })

fuse.search('fon')
// { ..., score: 0.3333333333333333 }

fuse.search('foo')
// { ..., score: 2.220446049250313e-16 }

Here's a runkit with a repro case: https://runkit.com/erquhart/fuse-exact-match-bug/3.0.0

Expected behavior

Exact match should have a score of 0, as it does when searching against a list of strings.

Screenshots

No response

Additional context

A related issue about this that didn't get any response and was closed as stale: https://github.com/krisk/Fuse/issues/717

erquhart commented 5 months ago

@krisk sorry for the at-mention, I'm just curious if you can shed light. This looks to be happening for multiple major versions. Is there any chance I'm holding it wrong?

github-actions[bot] commented 1 month ago

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

erquhart commented 1 month ago

Still an issue.

kamalesh100 commented 5 days ago

The number 2.220446049250313e-16 in decimal form is: 0.0000000000000002220446049250313

That's closest to 0.

erquhart commented 4 days ago

Ah that's a negative exponent! I can't recall if I encountered an actual problem from this or just eyeballed the number and thought it was wrong. Since it does work correctly when comparing with other numbers, I'll assume it's the latter, so this isn't a bug.

Thanks for the help @kamalesh100!