Solr通过edismax提升评分并打印评分规则

2024-02-16 01:48

本文主要是介绍Solr通过edismax提升评分并打印评分规则,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

首先看一下DisMax query parser的定义:

The DisMax query parser is designed to process simple phrases (without complex syntax) entered by users and to search for individual terms across several fields using different weighting (boosts) based on the significance of each field. Additional options enable users to influence the score based on rules specific to each use case

(independent of user input).

再看eDisMax(The Extended DisMax Query Parser)的定义:

The Extended DisMax (eDisMax) query parser is an improved version of the DisMax query parser,includes improved boost function: in Extended DisMax, the boost function is a multiplier rather than an addend, improving your boost results; the additive boost functions of DisMax (bf and bq) are also supported.

In addition to all the DisMax parameters, Extended DisMax includes these query parameters:
【The boost Parameter 】

A multivalued list of strings parsed as queries with scores multiplied by the score from the main query for all matching documents. This parameter is shorthand for wrapping the query produced by eDisMax using the BoostQParserPlugin

即通过boost参数可以在原有的评分基础上再乘以这个参数,该参数可以为某个field。


比如从Mysql中向solr导入以下数据:

+----+--------------------------------+--------+
| id | keyword                               | weight |
+----+--------------------------------+--------+
|  3 | 中国                                          |    1.0 |
|  4 | 美国人民                                  |    1.0 |
|  5 | 人民群众                                  |    1.0 |
|  6 | 美国人民                                  |    1.0 |
|  7 | 中国人民解放军                      |    2.0 |
|  8 | 中国很好,美国也不错          |   10.0 |
|  9 | chinese people                      |    1.0 |
| 10 | my god, you are chinese     |    1.0 |
| 11 | you are chinese people       |    1.0 |
| 12 | 中国中国                                 |    1.0 |
+----+--------------------------------+--------+

在执行查询时,可以通过设置debugQuery来打印评分规则(可以在Raw Query Parameters中设置debugQuery=true或者直接勾选debugQuery如下图所示),

例如,不进行boost提分,直接查询关键词:



返回结果中的评分详情:

"debug": {
    "rawquerystring": "keyword:中国",
    "querystring": "keyword:中国",
    "parsedquery": "(keyword:中国 keyword:china)/no_coord",
    "parsedquery_toString": "keyword:中国 keyword:china",
    "explain": {
      "3": "\n0.7724356 = sum of:\n  0.7724356 = weight(keyword:中国 in 0) [ClassicSimilarity], result of:\n    0.7724356 = score(doc=0,freq=1.0), product of:\n      0.4562129 = queryWeight, product of:\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        0.2694467 = queryNorm\n      1.6931472 = fieldWeight in 0, product of:\n        1.0 = tf(freq=1.0), with freq of:\n          1.0 = termFreq=1.0\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        1.0 = fieldNorm(doc=0)\n",
      "7": "\n0.24138615 = sum of:\n  0.24138615 = weight(keyword:中国 in 4) [ClassicSimilarity], result of:\n    0.24138615 = score(doc=4,freq=1.0), product of:\n      0.4562129 = queryWeight, product of:\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        0.2694467 = queryNorm\n      0.5291085 = fieldWeight in 4, product of:\n        1.0 = tf(freq=1.0), with freq of:\n          1.0 = termFreq=1.0\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        0.3125 = fieldNorm(doc=4)\n",
      "8": "\n0.3862178 = sum of:\n  0.3862178 = weight(keyword:中国 in 5) [ClassicSimilarity], result of:\n    0.3862178 = score(doc=5,freq=1.0), product of:\n      0.4562129 = queryWeight, product of:\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        0.2694467 = queryNorm\n      0.8465736 = fieldWeight in 5, product of:\n        1.0 = tf(freq=1.0), with freq of:\n          1.0 = termFreq=1.0\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        0.5 = fieldNorm(doc=5)\n",
      "12": "\n0.54619443 = sum of:\n  0.54619443 = weight(keyword:中国 in 9) [ClassicSimilarity], result of:\n    0.54619443 = score(doc=9,freq=2.0), product of:\n      0.4562129 = queryWeight, product of:\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        0.2694467 = queryNorm\n      1.1972358 = fieldWeight in 9, product of:\n        1.4142135 = tf(freq=2.0), with freq of:\n          2.0 = termFreq=2.0\n        1.6931472 = idf(docFreq=4, maxDocs=10)\n        0.5 = fieldNorm(doc=9)\n"
    },


当设置 edismax query方式以及boost参数以后(本例中用weight 列作为要提分的权重,lucene的原始评分乘以这个权重为最终得分),如:



评分详情:

"debug": {
    "rawquerystring": "keyword:中国",
    "querystring": "keyword:中国",
    "parsedquery": "BoostedQuery(boost(+(keyword:中国 keyword:china),float(weight)))",
    "parsedquery_toString": "boost(+(keyword:中国 keyword:china),float(weight))",
    "explain": {
      "3": "\n0.7724356 = boost(keyword:中国 keyword:china,float(weight)), product of:\n  0.7724356 = sum of:\n    0.7724356 = weight(keyword:中国 in 0) [ClassicSimilarity], result of:\n      0.7724356 = score(doc=0,freq=1.0), product of:\n        0.4562129 = queryWeight, product of:\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          0.2694467 = queryNorm\n        1.6931472 = fieldWeight in 0, product of:\n          1.0 = tf(freq=1.0), with freq of:\n            1.0 = termFreq=1.0\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          1.0 = fieldNorm(doc=0)\n  1.0 = float(weight)=1.0\n",
      "7": "\n0.4827723 = boost(keyword:中国 keyword:china,float(weight)), product of:\n  0.24138615 = sum of:\n    0.24138615 = weight(keyword:中国 in 4) [ClassicSimilarity], result of:\n      0.24138615 = score(doc=4,freq=1.0), product of:\n        0.4562129 = queryWeight, product of:\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          0.2694467 = queryNorm\n        0.5291085 = fieldWeight in 4, product of:\n          1.0 = tf(freq=1.0), with freq of:\n            1.0 = termFreq=1.0\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          0.3125 = fieldNorm(doc=4)\n  2.0 = float(weight)=2.0\n",
      "8": "\n3.862178 = boost(keyword:中国 keyword:china,float(weight)), product of:\n  0.3862178 = sum of:\n    0.3862178 = weight(keyword:中国 in 5) [ClassicSimilarity], result of:\n      0.3862178 = score(doc=5,freq=1.0), product of:\n        0.4562129 = queryWeight, product of:\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          0.2694467 = queryNorm\n        0.8465736 = fieldWeight in 5, product of:\n          1.0 = tf(freq=1.0), with freq of:\n            1.0 = termFreq=1.0\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          0.5 = fieldNorm(doc=5)\n  10.0 = float(weight)=10.0\n",
      "12": "\n0.54619443 = boost(keyword:中国 keyword:china,float(weight)), product of:\n  0.54619443 = sum of:\n    0.54619443 = weight(keyword:中国 in 9) [ClassicSimilarity], result of:\n      0.54619443 = score(doc=9,freq=2.0), product of:\n        0.4562129 = queryWeight, product of:\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          0.2694467 = queryNorm\n        1.1972358 = fieldWeight in 9, product of:\n          1.4142135 = tf(freq=2.0), with freq of:\n            2.0 = termFreq=2.0\n          1.6931472 = idf(docFreq=4, maxDocs=10)\n          0.5 = fieldNorm(doc=9)\n  1.0 = float(weight)=1.0\n"
    },


可以看到id为7的记录其weight为2.0, 评分提升了两倍,id为8的记录其weight为10.0, 评分提升了10倍.

这篇关于Solr通过edismax提升评分并打印评分规则的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/713154

相关文章

关于Gateway路由匹配规则解读

《关于Gateway路由匹配规则解读》本文详细介绍了SpringCloudGateway的路由匹配规则,包括基本概念、常用属性、实际应用以及注意事项,路由匹配规则决定了请求如何被转发到目标服务,是Ga... 目录Gateway路由匹配规则一、基本概念二、常用属性三、实际应用四、注意事项总结Gateway路由

Redis 多规则限流和防重复提交方案实现小结

《Redis多规则限流和防重复提交方案实现小结》本文主要介绍了Redis多规则限流和防重复提交方案实现小结,包括使用String结构和Zset结构来记录用户IP的访问次数,具有一定的参考价值,感兴趣... 目录一:使用 String 结构记录固定时间段内某用户 IP 访问某接口的次数二:使用 Zset 进行

使用DeepSeek API 结合VSCode提升开发效率

《使用DeepSeekAPI结合VSCode提升开发效率》:本文主要介绍DeepSeekAPI与VisualStudioCode(VSCode)结合使用,以提升软件开发效率,具有一定的参考价值... 目录引言准备工作安装必要的 VSCode 扩展配置 DeepSeek API1. 创建 API 请求文件2.

C#使用yield关键字实现提升迭代性能与效率

《C#使用yield关键字实现提升迭代性能与效率》yield关键字在C#中简化了数据迭代的方式,实现了按需生成数据,自动维护迭代状态,本文主要来聊聊如何使用yield关键字实现提升迭代性能与效率,感兴... 目录前言传统迭代和yield迭代方式对比yield延迟加载按需获取数据yield break显式示迭

poj 1734 (floyd求最小环并打印路径)

题意: 求图中的一个最小环,并打印路径。 解析: ans 保存最小环长度。 一直wa,最后终于找到原因,inf开太大爆掉了。。。 虽然0x3f3f3f3f用memset好用,但是还是有局限性。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#incl

java学习,进阶,提升

http://how2j.cn/k/hutool/hutool-brief/1930.html?p=73689

Solr 使用Facet分组过程中与分词的矛盾解决办法

对于一般查询而言  ,  分词和存储都是必要的  .  比如  CPU  类型  ”Intel  酷睿  2  双核  P7570”,  拆分成  ”Intel”,”  酷睿  ”,”P7570”  这样一些关键字并分别索引  ,  可能提供更好的搜索体验  .  但是如果将  CPU  作为 Facet  字段  ,  最好不进行分词  .  这样就造成了矛盾  ,  解决方法

Solr部署如何启动

Solr部署如何启动 Posted on 一月 10, 2013 in:  Solr入门 | 评论关闭 我刚接触solr,我要怎么启动,这是群里的朋友问得比较多的问题, solr最新版本下载地址: http://www.apache.org/dyn/closer.cgi/lucene/solr/ 1、准备环境 建立一个solr目录,把solr压缩包example目录下的内容复制

JAVA用最简单的方法来构建一个高可用的服务端,提升系统可用性

一、什么是提升系统的高可用性 JAVA服务端,顾名思义就是23体验网为用户提供服务的。停工时间,就是不能向用户提供服务的时间。高可用,就是系统具有高度可用性,尽量减少停工时间。如何用最简单的方法来搭建一个高效率可用的服务端JAVA呢? 停工的原因一般有: 服务器故障。例如服务器宕机,服务器网络出现问题,机房或者机架出现问题等;访问量急剧上升,导致服务器压力过大导致访问量急剧上升的原因;时间和

Adblock Plus官方规则Easylist China说明与反馈贴(2015.12.15)

-------------------------------特别说明--------------------------------------- 视频广告问题:因Adblock Plus的局限,存在以下现象,优酷、搜狐、17173黑屏并倒数;乐视、爱奇艺播放广告。因为这些视频网站的Flash播放器被植入了检测代码,而Adblock Plus无法修改播放器。 如需同时使用ads