olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.89k stars 548 forks source link

Results w/ same score sorting differently between IE and Chrome #395

Closed davidcorrigan714 closed 5 years ago

davidcorrigan714 commented 5 years ago

I'm indexing and searching a long list of product names & versions. That tends to lead to results with an identical match score. I've noticed that on IE, results with the same match score are sorted one way, but in chrome the results are sorted the other way. I happen to prefer the way it's sorting in Chrome and I believe that matches the order I added the items to the index. The index is prebuilt and loaded from JSON, so that side of things is consistent between my tests. Either way, I'm curious what the cause might be.

davidcorrigan714 commented 5 years ago

Sorting the results in my application was an improvement on both browsers so this doesn't matter to me anymore, but it might still be interesting to understanding how results with identical scores should be sorted.

olivernn commented 5 years ago

There isn't anything fancy going on with the sort, just using the plain old Array#sort provided by JavaScript. Because of this there is every possibility that different JavaScript engines might implement this differently, the stable vs non-stable sort in your case.

I would imagine that sorting the results based on some application specific heuristic will provide the best results in these cases.