SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Solr Community of China
© Copyright www.solr.cc
----风雨
lucene评分机制分析
风雨
2013年7月4日
Solr Community of China
www.solr.cc
议题
 一.名词解释(预备知识)
 二.相似度算法介绍VSM 介绍
 三.VSM对应lucene的打分公式推导
 四. Lucene评分公式的细化介绍
 五. 改变评分的一般策略
 六. 拍砖答疑时间
预估时间:1小时
Solr Community of China
www.solr.cc
一.名词解释(预备知识)
1. 分词: 研究生|研究|生产 研究生|研究生|产
2. Token:倒排表最小单位,即分词中 词
3. Term:query的最小单位,tilte:皇帝
4. Tf:一个term在一个文档中出现的次数
5. Idf:一个term在多少个文档中出现过
6. 向量运算:
Solr Community of China
www.solr.cc
二.常见相似度算法介绍VSM
Solr Community of China
www.solr.cc
三.VSM对应lucene的打分公式推导
 设:
 查询向量为Vq = <w(t1, q), w(t2, q), ……, w(tn, q)>
 文档向量为Vd = <w(t1, d), w(t2, d), ……, w(tn, d)>
 W=tf*idf
则:
 Vq*Vd = w(t1, q)*w(t1, d) + w(t2, q)*w(t2, d) + …… + w(tn ,q)*w(tn, d)
=tf(t1, q)*idf(t1, q)*tf(t1, d)*idf(t1, d) + …… + tf(tn,q)*idf(tn, q)*tf(tn,
d)*idf(tn, d)
Tf(t,q)=1, idf(t,q)约等于idf(t,d)
Solr Community of China
www.solr.cc
三.VSM对应lucene的打分公式推导
 Lucene采用的Similarity,认为在计算文档的向量长度的时候,每个Term的权重就丌再考
 虑在内了,而是全部为一(如果按权重考虑会有问题)
 查询语句中tf都为1,idf查询语句这篇小文档 即idf(t,q) = idf(t,d),得到如下公式
Solr Community of China
www.solr.cc
三.VSM对应lucene的打分公式推导
 代入余弦公式:
加上lucene自己的各种boost和coord
Solr Community of China
www.solr.cc
四. Lucene评分公式的细化介绍
 1协调因子 coord(q,d)
coord(q,d) = overlap/ maxOverlap
 overlap(命中查询个数)
 maxOverlap(总查询个数)
 搜索语句为: 图书名称:”红楼梦” || 作者:”红楼梦”
 doc1: 图书名称:红楼梦 作者:曹雪芹 coord(q,d) = 1/2
 doc2: 图书名称: 红楼梦 作者:红楼梦编委 coord(q,d) 2/2 (高)
Solr Community of China
www.solr.cc
四. Lucene评分公式的细化介绍
 2. 查询规范因子 queryNorm(q) (对排序无任何影响)
queryNorm(q) = 1/(q.getBoost()^2·∑( idf(t)·t.getBoost() )^2)
q.getBoost() 查询语句总权重(query上设置的boost)
t.getBoost() 子查询权重(tilte:红楼梦 desc:红楼梦)
Solr Community of China
www.solr.cc
 3.文档词频因子 tf(t in d)
tf(t in d) = Math.sqrt(freq)
 例如 搜索 图书名称:红楼梦
 文档1:图书名称:红楼梦tf=1
 文档2:图书名称:红楼梦曹雪芹签名版红楼梦 tf=1.414 (高)
Solr Community of China
www.solr.cc
四. Lucene评分公式的细化介绍
4. 文档出现频率因子 idf(t)
idf(t) = 1.0 + log(numDocs/(docFreq+1))
 numDocs(总文档数)
 docFreq(有几个文档中出现了查询的词)
 例如搜索语句为:图书名称:“红楼梦” || 作者:“曹雪芹” 总文档数为1000
 如果图书名称中包含图书名称“红楼梦”的文档数为100 idf= 2.0
 作者名称中包含作者“曹雪芹”的文档数为10 idf= 3.0 (高)
Solr Community of China
www.solr.cc
四. Lucene评分公式的细化介绍
5. 查询权重t.getBoost
itemName:红楼梦^10.0 itemDesc:红楼梦
Solr Community of China
www.solr.cc
四. Lucene评分公式的细化介绍
6. 标准化因子 norm(t,d)
norm(t,d) = doc.getBoost()· lengthNorm· ∏ f.getBoost() (注意:4.0以后没有了 doc.getBoost())
lengthNorm = 1.0 / Math.sqrt(numTerms)
 doc.getBoost() (在每个文档上设置的权重)
 f.getBoost() (在每个字段上设置的权重
 lengthNorm = 1.0 / Math.sqrt(numTerms)
 表示字段长度对打分的影响
 例如:文档1:图书名称:红楼梦 lengthNorm = 1/1.7 (高)
 文档2:图书名称: 红楼梦新刊第28期 = 1/3
Solr Community of China
www.solr.cc
四. Lucene评分公式的细化介绍
将上面1-6部分细化的部分代入上面公式得到
score(q,d) = (overlap / maxOverlap )·(1/(q.getBoost()^2·∑( idf(t)·t.getBoost() )^2
) ) · ∑( tf(t in d)·idf(t)^2·t.getBoost()· doc.getBoost()· lengthNorm· ∏ f.getBoost() )
查询时确定: 1、2、3、4、5
索引时确定:6
Solr Community of China
www.solr.cc
五. 改变评分的一般策略
API调用:
索引时刻:filed boost设置, doc boost设置
4.0之前:doc.setBoost(5.0f);
查询时刻: queryBoost设置
Solr Community of China
www.solr.cc
五. 改变评分的一般策略
重写:Similarity (继承DefaultSimilarity或TFIDFSimilarity)
Solr Community of China
www.solr.cc
五. 改变评分的一般策略
使用:explain 查看评分细节,修改评分策略
Solr Community of China
www.solr.cc
六. 拍砖答疑时间
Solr Community of China
www.solr.cc
谢谢!

Contenu connexe

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Solr中国7月14日讲座v2

  • 1. Solr Community of China © Copyright www.solr.cc ----风雨 lucene评分机制分析 风雨 2013年7月4日
  • 2. Solr Community of China www.solr.cc 议题  一.名词解释(预备知识)  二.相似度算法介绍VSM 介绍  三.VSM对应lucene的打分公式推导  四. Lucene评分公式的细化介绍  五. 改变评分的一般策略  六. 拍砖答疑时间 预估时间:1小时
  • 3. Solr Community of China www.solr.cc 一.名词解释(预备知识) 1. 分词: 研究生|研究|生产 研究生|研究生|产 2. Token:倒排表最小单位,即分词中 词 3. Term:query的最小单位,tilte:皇帝 4. Tf:一个term在一个文档中出现的次数 5. Idf:一个term在多少个文档中出现过 6. 向量运算:
  • 4. Solr Community of China www.solr.cc 二.常见相似度算法介绍VSM
  • 5. Solr Community of China www.solr.cc 三.VSM对应lucene的打分公式推导  设:  查询向量为Vq = <w(t1, q), w(t2, q), ……, w(tn, q)>  文档向量为Vd = <w(t1, d), w(t2, d), ……, w(tn, d)>  W=tf*idf 则:  Vq*Vd = w(t1, q)*w(t1, d) + w(t2, q)*w(t2, d) + …… + w(tn ,q)*w(tn, d) =tf(t1, q)*idf(t1, q)*tf(t1, d)*idf(t1, d) + …… + tf(tn,q)*idf(tn, q)*tf(tn, d)*idf(tn, d) Tf(t,q)=1, idf(t,q)约等于idf(t,d)
  • 6. Solr Community of China www.solr.cc 三.VSM对应lucene的打分公式推导  Lucene采用的Similarity,认为在计算文档的向量长度的时候,每个Term的权重就丌再考  虑在内了,而是全部为一(如果按权重考虑会有问题)  查询语句中tf都为1,idf查询语句这篇小文档 即idf(t,q) = idf(t,d),得到如下公式
  • 7. Solr Community of China www.solr.cc 三.VSM对应lucene的打分公式推导  代入余弦公式: 加上lucene自己的各种boost和coord
  • 8. Solr Community of China www.solr.cc 四. Lucene评分公式的细化介绍  1协调因子 coord(q,d) coord(q,d) = overlap/ maxOverlap  overlap(命中查询个数)  maxOverlap(总查询个数)  搜索语句为: 图书名称:”红楼梦” || 作者:”红楼梦”  doc1: 图书名称:红楼梦 作者:曹雪芹 coord(q,d) = 1/2  doc2: 图书名称: 红楼梦 作者:红楼梦编委 coord(q,d) 2/2 (高)
  • 9. Solr Community of China www.solr.cc 四. Lucene评分公式的细化介绍  2. 查询规范因子 queryNorm(q) (对排序无任何影响) queryNorm(q) = 1/(q.getBoost()^2·∑( idf(t)·t.getBoost() )^2) q.getBoost() 查询语句总权重(query上设置的boost) t.getBoost() 子查询权重(tilte:红楼梦 desc:红楼梦)
  • 10. Solr Community of China www.solr.cc  3.文档词频因子 tf(t in d) tf(t in d) = Math.sqrt(freq)  例如 搜索 图书名称:红楼梦  文档1:图书名称:红楼梦tf=1  文档2:图书名称:红楼梦曹雪芹签名版红楼梦 tf=1.414 (高)
  • 11. Solr Community of China www.solr.cc 四. Lucene评分公式的细化介绍 4. 文档出现频率因子 idf(t) idf(t) = 1.0 + log(numDocs/(docFreq+1))  numDocs(总文档数)  docFreq(有几个文档中出现了查询的词)  例如搜索语句为:图书名称:“红楼梦” || 作者:“曹雪芹” 总文档数为1000  如果图书名称中包含图书名称“红楼梦”的文档数为100 idf= 2.0  作者名称中包含作者“曹雪芹”的文档数为10 idf= 3.0 (高)
  • 12. Solr Community of China www.solr.cc 四. Lucene评分公式的细化介绍 5. 查询权重t.getBoost itemName:红楼梦^10.0 itemDesc:红楼梦
  • 13. Solr Community of China www.solr.cc 四. Lucene评分公式的细化介绍 6. 标准化因子 norm(t,d) norm(t,d) = doc.getBoost()· lengthNorm· ∏ f.getBoost() (注意:4.0以后没有了 doc.getBoost()) lengthNorm = 1.0 / Math.sqrt(numTerms)  doc.getBoost() (在每个文档上设置的权重)  f.getBoost() (在每个字段上设置的权重  lengthNorm = 1.0 / Math.sqrt(numTerms)  表示字段长度对打分的影响  例如:文档1:图书名称:红楼梦 lengthNorm = 1/1.7 (高)  文档2:图书名称: 红楼梦新刊第28期 = 1/3
  • 14. Solr Community of China www.solr.cc 四. Lucene评分公式的细化介绍 将上面1-6部分细化的部分代入上面公式得到 score(q,d) = (overlap / maxOverlap )·(1/(q.getBoost()^2·∑( idf(t)·t.getBoost() )^2 ) ) · ∑( tf(t in d)·idf(t)^2·t.getBoost()· doc.getBoost()· lengthNorm· ∏ f.getBoost() ) 查询时确定: 1、2、3、4、5 索引时确定:6
  • 15. Solr Community of China www.solr.cc 五. 改变评分的一般策略 API调用: 索引时刻:filed boost设置, doc boost设置 4.0之前:doc.setBoost(5.0f); 查询时刻: queryBoost设置
  • 16. Solr Community of China www.solr.cc 五. 改变评分的一般策略 重写:Similarity (继承DefaultSimilarity或TFIDFSimilarity)
  • 17. Solr Community of China www.solr.cc 五. 改变评分的一般策略 使用:explain 查看评分细节,修改评分策略
  • 18. Solr Community of China www.solr.cc 六. 拍砖答疑时间
  • 19. Solr Community of China www.solr.cc 谢谢!