首页 > 解决方案 > 基于分数和字段值的 Apache Solr 排序

问题描述

我使用了以下请求

http://localhost:8983/solr/test6/select?q=*:*&sort=product(score,hits)%20desc

根据 Apache Solr 确定的相关性分数乘以称为命中(整数)的字段对结果进行排序。

但是,我收到以下错误消息:

{   "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}}

为什么 sort 在以下情况下无法正确输入函数值:

http://localhost:8983/solr/test6/select?q=*:*&sort=score%20desc

http://localhost:8983/solr/test6/select?q=*:*&sort=hits%20desc

不应用功能时工作?

注意http://localhost:8983/solr/test6/select?q=*:*&sort=product(hits,2)%20desc我添加 product() 函数的地方也返回相同的错误消息。

标签: apachesortingsearchsolrfield

解决方案


score值并不是真正的字段 - 因此您不能使用函数在排序子句中对其进行操作。

相反,您可以使用乘法提升boost(如果您使用的是 edismax)来实现您想要的:&boost=hits. 您可能想要使用log(hits)或类似的东西(recip例如)来避免因点击次数的微小变化而导致得分的巨大差异。


推荐阅读