进阶-第25__深度探秘搜索技术_深入揭秘lucene的相关度分数算法

 

我们boolean model、TF/IDF、vector space model

 

深入讲解TF/IDF算法,在lucene中,底层,到底进行TF/IDF算法计算的一个完整的公式是什么?

 

0、boolean model

当我们搜索:

query: hello world

 

"match": {

        "title": "hello world"

}

底层会转换为:

"bool": {

        "should": [

                 {

                         "match": {

                                  "title": "hello"

                         }

                 },

                 {

                         "natch": {

                                  "title": "world"

                         }

                 }

        ]

}

 

普通multivalue搜索,转换为bool搜索,boolean model

 

1、lucene practical scoring function

 

practical scoring function,来计算一个query对一个doc的分数的公式,该函数会使用一个公式来计算

 

score(q,d)  = 

            queryNorm(q) 

          · coord(q,d)   

          · ∑ (          

                tf(t in d)  

              · idf(t)2     

              · t.getBoost()

              · norm(t,d)   

            ) (t in q)

 

score(q,d) score(q,d) is the relevance score of document d for query q.

 

这个公式的最终结果,就是说是一个query(叫做q),对一个doc(叫做d)的最终的总评分

 

queryNorm(q) is the query normalization factor (new).

 

queryNorm,是用来让一个doc的分数处于一个合理的区间内,不要太离谱,举个例子,一个doc分数是10000,一个doc分数是0.1,你们说好不好,肯定不好

 

 

coord(q,d) is the coordination factor (new).

 

简单来说,就是对更加匹配的doc,进行一些分数上的成倍的奖励

 

 

The sum of the weights for each term t in the query q for document d.

 

∑:求和的符号

 

 

 

∑ (t in q):query中每个term,query = hello world,query中的term就包含了hello和world

 

query中每个term对doc的分数,进行求和,多个term对一个doc的分数,组成一个vector space,然后计算吗,就在这一步

 

 

tf(t in d) is the term frequency for term t in document d.

 

计算每一个term对doc的分数的时候,就是TF/IDF算法

 

 

idf(t) is the inverse document frequency for term t.

 

 

t.getBoost() is the boost that has been applied to the query (new).  权重你查询时是否增强,根据你的增强否,进行相应的变化

 

 

norm(t,d) is the field-length norm, combined with the index-time field-level boost, if any. (new).

 

 

2、query normalization factor

 

queryNorm = 1 / √sumOfSquaredWeights

 

sumOfSquaredWeights = 所有term的IDF分数之和,开一个平方根,然后做一个平方根分之1

主要是为了将分数进行规范化 --> 开平方根,首先数据就变小了 --> 然后还用1去除以这个平方根,分数就会很小 --> 1.几 / 零点几

分数就不会出现几万,几十万,那样的离谱的分数

 

3、query coodination

 

奖励那些匹配更多字符的doc更多的分数

 

Document 1 with hello → score: 1.5

Document 2 with hello world → score: 3.0

Document 3 with hello world java → score: 4.5

 

Document 1 with hello → score: 1.5 * 1 / 3 = 0.5

Document 2 with hello world → score: 3.0 * 2 / 3 = 2.0

Document 3 with hello world java → score: 4.5 * 3 / 3 = 4.5

 

把计算出来的总分数 * 匹配上的term数量 / 总的term数量,让匹配不同term/query数量的doc,分数之间拉开差距

 

4、field level boost

对某个query 设置他的boost,增强它的权重。

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值