Search code examples
sortingsolrlucenefull-text-searchsearch-engine

Rounding score on 2 decimals in sort - SOLR 4.2


How to round score of search result on 2 decimals?

Can I use, rounded score in sort?

I need somethink like:

/?q=term&sort=round(score, 2) desc, orders desc

in Solr version 4.2

I want to sort search result by field orders, but I got not relevant result first. I got a few thousand results. So, I want to make compromise between field orders and score.


Solution

  • Function Queries require an indexed field and score is not a real field, thus you can't use it. But I like femtoRgon's approach. Here is an other version

    You could use rint()/product() in combination with query()

    q=rint(product(query({!v="author:alice"}) ,100))&defType=func&fl=*,score&sort=score desc, author desc
    

    Substitue author:alice with your query. I am not sure what the performance impact is, since it runs subqueries. You will have to check that.