Solr功能查询:如何使用“分数"?用于创建自定义评分的字段 [英] Solr Function Query : How to use "score" field for creating custom scoring

查看:363
本文介绍了Solr功能查询:如何使用“分数"?用于创建自定义评分的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过广泛搜索并遇到诸如此类的答案-

After searching extensively and coming across answers such as these -

> Solr:按分数排序;一个int字段值

使用函数查询来提高Solr中的分数

我仍然无法解决以下问题:

I am still unable to solve the following problem :

如何使用文档的分数"字段创建新的评分功能并相应地对结果进行排名.像这样-

new_score =得分* my_other_field

new_score = score * my_other_field

当前查询-

http://localhost:8984/solr/suggest_new/select?q=tom&wt=json&indent=true&bq=_val_:"product(score,count_of_searches)"

这是我在Elasticsearch中要做的-

This is something I would have done in Elasticsearch -

"script_score" : {
    "script" : "_score * doc['my_numeric_field'].value"
}

请帮助/指出正确的链接.非常感谢 ! (注意:Solr版本:4.10.4)

Please help/ point out correct links. Thanks a lot ! (Note : Solr Version : 4.10.4)

推荐答案

在使用Dismax或eDismax时,您应该可以只使用字段 bf (增强功能)参数,并用名称填充数字字段.

When using Dismax or eDismax you should be able to just use the field bf (Boost Functions) parameter and fill it with the name of your numeric field.

示例

我有一个索引,其中的文档除其他字段外还包含一个名为 first_publication_year 的数值.当我对索引运行matchAllQuery *:*时,所有文档的得分均为1.这很容易看到 bf 参数的效果,因为1很容易被除数.该示例仍然可以进行任何查询.

I have an index with documents that contain among other fields a numeric value named first_publication_year. When I run a matchAllQuery *:* against my index, all documents will get a score of 1. This makes the effect of the bf parameter easier to see, as 1 is an easy divisor. The sample would go with any query though.

/select?q=*:*

结果

{
  "responseHeader": {
    "status": 0,
    "QTime": 1
  },
  "response": {
    "numFound": 10007277,
    "start": 0,
    "maxScore": 1,
    "docs": [
      {
        "first_publication_year": 2002,
        "score": 1
      }
    ]
  }
}

现在,我想基于该字段增强文档,因此我将该字段名称添加为

Now I want to boost the documents based on that field, so I add that field name as bf parameter

/select?q=*:*&bf=first_publication_year

结果

{
  "responseHeader": {
    "status": 0,
    "QTime": 1
  },
  "response": {
    "numFound": 10007277,
    "start": 0,
    "maxScore": 1425.5273,
    "docs": [
      {
        "first_publication_year": 2015,
        "score": 1425.5273
      }
    ]
  }
}

如果您认为提升幅度太小,则可以使用

If you think that the boost is too meagre you may adjust this with function queries. This sample multiplies the first publication year with 10.

/select?q=*:*&bf=product(first_publication_year,10)

结果

{
  "responseHeader": {
    "status": 0,
    "QTime": 465
  },
  "response": {
    "numFound": 10007277,
    "start": 0,
    "maxScore": 14248.908,
    "docs": [
      {
        "first_publication_year": 2015,
        "score": 14248.908
      }
    ]
  }
}

参考

这也记录在《 Solr参考手册》 .

bf(增强功能)参数

bf参数指定用于构造FunctionQueries的函数(具有可选的boost),这些函数将作为影响子句的可选子句添加到用户的主查询中.可以使用Solr原生支持的任何功能以及提升值.例如:

The bf parameter specifies functions (with optional boosts) that will be used to construct FunctionQueries which will be added to the user's main query as optional clauses that will influence the score. Any function supported natively by Solr can be used, along with a boost value. For example:

recip(rord(myfield),1,2,3)^1.5

这篇关于Solr功能查询:如何使用“分数"?用于创建自定义评分的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆