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

Scores that are equal to minimumScore are excluded #16

Open
SeanLMcCullough opened this issue Aug 5, 2021 · 1 comment
Open

Scores that are equal to minimumScore are excluded #16

SeanLMcCullough opened this issue Aug 5, 2021 · 1 comment

Comments

@SeanLMcCullough
Copy link

This may or may not be a bug, or perhaps an ambiguity in the documentation.

If minimumScore = 0, items with score = 0 will not be returned in the result list. Setting a negative value is required.

Should this be >= instead of >? Or should the documentation reflect this logic?

@fwextensions
Copy link
Owner

Apologies for the slow response.

You're right, the documentation is ambiguous. The entry for minimumScore says An optional value that specifies the minimum score an item must have to appear in the results, implying >=, but then says Defaults to 0, so items that don't match the full query will not be returned., implying >.

The documentation for the search() method has the clearest specification for how the minimumScore is used: Items with scores that are <= the minimumScore option (defaults to 0) are not returned, unless the query is falsy, in which case all of the items are returned, sorted alphabetically.

In practice, the difference between >= and > won't be noticeable, as scores are unlikely to be an exact float like 0.4, so you probably won't miss any expected results (and they'd be the poorest match anyway).

The obvious case is the one you point out, when minimumScore = 0. If the query is empty, minimumScore is ignored and all results are returned, as described above. So if you want all items returned, even if they don't match at all, then you'll need to set the option to -1.

I think the most common use case is not wanting non-matches in the results, which is why the code works as it does currently. If I changed the check to >=, people who wanted to filter out non-matches would have to remember to set minimumScore = 0.0001 or something.

Perhaps the solution is another option, like includeNonMatches, which would default to false. Then zero scores could be handled based on that flag, and the check on minimumScore could use >=, making the "minimum" part of the name more accurate. However, this could also lead to somewhat strange results, like { minimumScore: 0.4, includeNonMatches: true }, which would return items with score: 0 but not with score: 0.3.

Happy to take other suggestions as well. Maybe just clarifying the minimumScore docs would be simplest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants