如何使用“分数"用于创建自定义评分的字段 [英] How to use "score" field for creating custom scoring

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

问题描述

在广泛搜索并遇到诸如此类的答案之后 -

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 (Boost Functions) 参数并用名称填充它的数字字段.

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
      }
    ]
  }
}

现在我想基于该字段提升文档,所以我将该字段名称添加为 bf 参数

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
      }
    ]
  }
}

如果您认为提升太微薄,您可以使用 函数查询.此示例将第一个出版年份乘以 10.

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(Boost 函数)参数

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

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

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

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