Use function query for boosting score in Solr
Asked Answered
R

2

7

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.

Roentgenology answered 9/11, 2013 at 10:38 Comment(1)
Possible duplicate of Solr Function Query : How to use "score" field for creating custom scoringCrossway
T
2

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)"
Thisbee answered 10/11, 2013 at 2:45 Comment(1)
Thank you for your answer. We will try this solution.Roentgenology
C
1

Use query() function to get the value of 'score' instead.

So if you're trying for this: new_score = score * popularity , use the following format.

q=searchterm&sort=product(query($q),popularity) desc

query($q) - returns the TF-IDF score for the query. So this is the equivalent of using the 'score' field.

Crossway answered 23/1, 2017 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.