Reputation: 1322
I used the following request
http://localhost:8983/solr/test6/select?q=*:*&sort=product(score,hits)%20desc
to sort results based on their relevancy score as determined by Apache Solr multiplied by a field called hits (integers).
However, I receive the following error message:
{ "responseHeader":{
"status":400,
"QTime":0,
"params":{
"q":"*:*",
"sort":"product(score,hits) desc"}}, "error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"sort param could not be parsed as a query, and is not a field that exists in the index: product(score,hits)",
"code":400}}
Why is it that sort cannot correctly input the function value when:
http://localhost:8983/solr/test6/select?q=*:*&sort=score%20desc
http://localhost:8983/solr/test6/select?q=*:*&sort=hits%20desc
work when a function isn't applied?
NOTE: http://localhost:8983/solr/test6/select?q=*:*&sort=product(hits,2)%20desc
where I added the product() function also returns the same error message.
Upvotes: 2
Views: 644
Reputation: 52902
The score
value isn't really a field - so you can't use a function to manipulate it in the sort clause.
Instead you can use a multiplicative boost through boost
(if you're using edismax) to achieve what you want: &boost=hits
. You might want to use log(hits)
or something similar (recip
for example) instead to avoid large differences in score for just small changes in the number of hits.
Upvotes: 3