Use function query for boosting score in Solr

Krutal Modi picture Krutal Modi · Nov 9, 2013 · Viewed 7.7k times · Source

I working on a Solr 4 for optimizing my solr results rank based on popularity rank stored in Index.

Now when someone searches, apart from relevancy rank, I want to influence relevancy rank using popularity rank. The simplest formula could be:

new relavancy rank = score * popularityrank

I have been looking at Solr function query at http://wiki.apache.org/solr/FunctionQuery#product to achieve the same however, I'm not sure how to get it to work. I didn't get how to get score multiplied using product function. Trying to get it done, I always get error as field not defined.

Now I can use boost as defined here How to boost fields in solr, but I have additional logic/requirement where I want to use functional query provided by Solr.

For example, I have tried with following simple query that seems to work

http://solr:8983/solr/select?q=hp%20laptop&defType=edismax&fl=Id,Name,score&bf=product%28$v1,$v2%29&v1=Id&v2=2

Now, for my actual requirement, I want to take score as $v2, however I am not able to find how to do this.

Any help is highly appreicated.

Answer

Srikanth Venugopalan picture Srikanth Venugopalan · Nov 10, 2013

You can try using the _val_ hook provided by Solr.

For instance, in order to sort by score * popularityrank, try using this

http://solr:8983/solr/select?q=hp%20laptop&_val_="product(score,popularityrank)"