olivernn / lunr.js

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

Score range #290

Closed myalgo closed 7 years ago

myalgo commented 7 years ago

I would like to show relevance of search results. However not sure the range of score returned. I have seen score ranges from approx 0.001x to 3.x.

olivernn commented 7 years ago

The score returned probably isn't useful for anything other than sorting. I.e. you won't be able to use it to say a document is 83% relevant to a query.

Lunr treats documents and queries as many dimensional vectors, and then uses a technique based on cosine similarity to calculate how similar the vectors are. From the linked article you would imagine the scores would range from 0 to 1. However, due to field boosts and other implementation details of the way Lunr scores this is not true of the returned score.

The closest you might be able to get is to bucket the results into something like "high", "medium" or "low" relative to each other, though I'm not sure how useful that would be.