lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.67k stars 133 forks source link

Results Sort #192

Closed oasiz closed 1 year ago

oasiz commented 1 year ago

Hi, hope you are well!

Is there a way of sorting the results by highest score (first)?

I tried adding this but it doesn't seem to work:

.sort(function(a, b){return b.score - a.score})

Appreciate your help :-)

lucaong commented 1 year ago

Hi @oasiz , the results are always returned by MiniSearch in order of descending score (highest score first), so you do not need to re-sort them.

It is possible that something in your code causes the order to change? If you can share some code I might be able to help identify the problem.

lucaong commented 1 year ago

Hi @oasiz , I am going to close this, as it does not seem to be an issue with the library (see this JSbin demonstrating that results are returned highest score first).

If you can provide some code, comment on this thread, and I am happy to help you debug your specific issue.

oasiz commented 1 year ago

Hi Luca. Apologies for not replying sooner, it’s been a hectic few days!

Yes you are absolutely right, it was code I had introduced (callback function) that had somehow messed up the order. Whoops!

Thanks for getting back to me, I hope you have a fantastic Christmas and New Year 😃

lucaong commented 1 year ago

Good to hear you solved it :) Have a great time too!!