通过多个字段提升的总和得到最终分数

Get final score by sum of multiple fields boost

我想构建一个搜索,该搜索优先考虑字段匹配的数量,而不是一个字段优先于另一个字段。所有字段都将具有相同的提升值,最终分数应通过匹配字段提升的总和来计算。如果全文匹配两个字段,每个字段都有1个boost,则最终得分为1 + 1 = 2。

让我们举个例子:

class Event < ApplicationRecord searchable do text :title text :category text :artist_name end end

假设我有两个事件:

事件 1: 姓名: "Christmas festival" 艺术家姓名: "AC/DC"

事件 2: 姓名: "New year festival" 艺术家姓名: "Queen"

因此,如果用户只搜索 "festival",则两个事件都会 return 得到相同的分数,因为它与两个事件的名称相匹配。 但是,如果用户搜索 "festival AC/DC",我想首先 return Event 1 或者只是 Event 1因为它匹配事件名称(节日)和艺术家名称 (AC/DC)。而 Event 2 正好匹配事件名称(节日)。 事件 1 得分应为 2,而 事件 2 得分应为 1。

关于我该怎么做的任何建议?这可能吗?

看来您混淆了得分和提升,我认为您的问题应该标题为通过对每个字段得分求和来计算总分(不管提升)。

字段分数是根据字段匹配计算的,它们可以应用任意一组加法或乘法提升(函数 and/or 匹配子查询)。但最后你想要的是通过对每个领域得分求和来计算全局得分,而不是提升本身。

例如,

DisMax 查询解析器精确地允许您使用 tie(决胜局)参数来控制最终分数的计算方式:

The tie parameter specifies a float value (which should be something much less than 1) to use as tiebreaker in DisMax queries.

When a term from the user’s input is tested against multiple fields, more than one field may match. If so, each field will generate a different score based on how common that word is in that field (for each document relative to all other documents). The tie parameter lets you control how much the final score of the query will be influenced by the scores of the lower scoring fields compared to the highest scoring field.

A value of "0.0" - the default - makes the query a pure "disjunction max query": that is, only the maximum scoring subquery contributes to the final score. A value of "1.0" makes the query a pure "disjunction sum query" where it doesn’t matter what the maximum scoring sub query is, because the final score will be the sum of the subquery scores. Typically a low value, such as 0.1, is useful.

在您的情况下,您需要一个 析取和查询 ,因此您可能希望将 tie 设置为 1.0