相关性和相关性算分
- 相关性 -relevance
- 搜索的相关性算分,描述了一个文档和查询语句匹配的程序。es会对每个匹配查询条件的结果进行算分_score
-
打分的本质是排序,需要把最符合用户需求的文档排在前面。es 5之前,默认的相关性算分采用tf-idf,现在采用bm25
词频tf
- term frequency:检索词在一篇文档中出现的频率
- 检索词出现的次数除以文档的总字数
- 度量一条查询和结果文档的相关性的简单方法:简单将搜索中每一个词的tf进行相加
- tf(区块链)+tf(的)+tf(应用)
- stop word
- “的”在文档中出现了很多次,但是对贡献相关度几乎没有用处,不应该考虑他们的tf
逆文档频率idf
- df:检索词在所有文档中出现的频率
- “区块链”在相对比较少的文档中出现
- “应用”在相对比较多的文档中出现
- “stop word”在大量的文档中出现
- inverse docement frequency:简单说 = log(全部文档数/检索词出现过的文档总数)
- tf-idf本质上就是将tf求和变成了加权求和
-
tf(区块链)* idf(区块链)+ tf(的) * idf(的)+ tf(应用) * idf(应用)
-
tf-idf概念
lucene中的tf-idf评分公式
bm25
定制similarity
通过explain api 查看tf-idf
boosting relevance
- boosting是控制相关度的一种手段
- 索引,字段或者查询子条件
- 参数boost的含义
- 当boost>1是,打分的相关度相对性提升
- 当0<boost<1时,打分的权重相对性降低
- 当boost<0时,共享负分
回顾
- 什么是相关性&相关性算分
- tf-idf/bm25
- 在elasticsearch中定制相关度算法的参数
- es中可以对索引,字段,分别设置boosting参数
PUT testscore
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"properties": {
"content": {
"type": "text"
}
}
}
}
PUT testscore/_bulk
{ "index": { "_id": 1 }}
{ "content":"we use Elasticsearch to power the search" }
{ "index": { "_id": 2 }}
{ "content":"we like elasticsearch" }
{ "index": { "_id": 3 }}
{ "content":"The scoring of documents is caculated by the scoring formula" }
{ "index": { "_id": 4 }}
{ "content":"you know, for search" }
POST /testscore/_search
{
//"explain": true,
"query": {
"match": {
"content":"you"
//"content": "elasticsearch"
//"content":"the"
//"content": "the elasticsearch"
}
}
}
POST testscore/_search
{
"query": {
"boosting" : {
"positive" : {
"term" : {
"content" : "elasticsearch"
}
},
"negative" : {
"term" : {
"content" : "like"
}
},
"negative_boost" : 0.2
}
}
}
POST tmdb/_search
{
"_source": ["title","overview"],
"query": {
"more_like_this": {
"fields": [
"title^10","overview"
],
"like": [{"_id":"14191"}],
"min_term_freq": 1,
"max_query_terms": 12
}
}
}