-
-
Notifications
You must be signed in to change notification settings - Fork 626
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
feat: sort by score (most relevant first) when searching #671
Conversation
Thank you for this PR @danielsaul I think that |
I did consider this and is exactly what I did initially, so happy to swap back to that. The reason I didn't was so that we could expose the direction parameter, and allow sorting by the score in ascending order. It's not really possible to add direction as an additional parameter to Having said that, not sure why you would ever want to sort by score ascending 🤷 so maybe not a concern. I'll also double-check that sortByScoring won't have adverse affects on chaining a subsequent sortBy for example, but I can't imagine it would. |
Exactly, sometimes the best option is no option 😄 And anyway they can always |
Cool! Simplified and updated PR description 👍 |
Types of changes
Description
I found when testing my search, that I was receiving strange results, with relevant ones mixed in with not so relevant ones. I spent a while digging, and found that the results are not being sorted at all.
When you perform a search, it is normally expected that the results will be sorted by the most relevant results first.
The existing
search()
method does not do this, and it is not possible to usesortBy()
to sort by the underlying full text search score from LokiDB.LokiDB offers a method to
sortByScoring()
which must be used to ensure the most relevant results are returned.https://github.com/LokiJS-Forge/LokiDB/blob/master/packages/loki/src/result_set.ts#L377
https://github.com/LokiJS-Forge/LokiDB/blob/master/packages/full-text-search/spec/generic/full_text_search.spec.ts#L200
Therefore
search()
will now callsortByScoring()
within it by default, sorting by the search score descending, to provide the most relevant results first.Checklist: