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

Boost a document? #291

Closed rbren closed 6 years ago

rbren commented 7 years ago

I have certain documents I want to boost over others (e.g. "blog post" pages should be slightly preferred over "user" pages). Is there any way to do this currently? If not, is it a viable feature?

Great library by the way, it's been a big help.

Thanks, -Bobby

olivernn commented 7 years ago

I don't think this is something that can be done currently with Lunr. Scores are always based on how 'similar' the query is to a document.

I think the best a way would be to layer this kind of boost or score modification on top of the Lunr results. With the id returned by Lunr for the matching documents, you could lookup the 'type' of document (either blog post, or user page) and then apply a modifier to the returned score. I.e. if it is a blog post, multiply the score by some small amount, imitating a boost.

The downside is that you would end up having to sort the results again, but depending on the result set size this might not be too big a deal.

I don't think this is something that will end up in Lunr anytime soon, the current architecture just isn't set up to be able to handle it.