【大数据开发运维解决方案】Solr6.2默认相似性算法检索匹配得分高于5.1版本问题分析

简介: 我们之前使用的solr版本是solr5.1,分词器使用的是jcseg1.9.6,后续接触了Solr6.2,分词器使用的是jcseg2.6.0,发现同一个Oracle库的同一套表数据,分别使用solr5.1和solr6.2版本的模板collection配置集做相同的字段配置并成功做索引后,做相同查询,solr6.2检索文档score远高于solr5.1,下面是我们使用的两个solr环境以及另一个单机solr测试环境的基本情况:

Solr6.2默认相似性算法检索匹配得分高于5.1版本问题分析

注意:
我们之前使用的solr版本是solr5.1,分词器使用的是jcseg1.9.6,后续接触了Solr6.2,分词器使用的是jcseg2.6.0,发现同一个Oracle库的同一套表数据,分别使用solr5.1和solr6.2版本的模板collection配置集做相同的字段配置并成功做索引后,做相同查询,solr6.2检索文档score远高于solr5.1,下面是我们使用的两个solr环境以及另一个单机solr测试环境的基本情况:

大数据环境 solr版本
CDH Solr5.1
华为云 Solr6.2
单机 开源Solr6.2

一、问题重现

现有华为云solr6.2和cdh5.1以及开源solr6.2三个环境的solr,索引的数据均从同一个oracle11.2.0.4库表用相同的逻辑取数据,collection或core名字分别为uoc-buyer1、uoc-buyer、uoc-buyer,现分别从三个环境做下面问题查询:

q=engname%3A(ADNAN+UL+HAQ)%5E5+buyeraddr%3A(PP+NO+AF1401302+ADD%5C%3ATOBA+TEK+SINGH%2CPAKISTAN)%5E2+flag%3A(0%5E2+1%5E1)
&fq=%7B!frange+l%3D1.8%7Dquery(%24q)
&fq=-accuracylel%3A1
&fq=countrycode%3APAK
&fq=flag%3A0
&sort=flag+asc%2Caccuracylel+desc%2Cscore+desc
&fl=chnname%2Cengname%2Cbuyeraddr%2Cpuppetbn%2Cflag%2Ctableflag%2Cscore%2Ccountrycode
&wt=json
&indent=true

开源及华为云solr6.2检索得分:
image.png

二、问题分析

1、问题原因是否由于分词器版本不一致导致

因为我们之前开始时使用的是solr5.1,相关代码开发和相识度分数认定的分数线也是基于solr5.1来做的,所以在后续将collection逻辑拿到6.2版本的开源和华为云solr后,发现分数差别很大。
首先怀疑是不是分词器导致的,因为两个solr6.2分词器使用的是jcseg2.6.0,而cdh的solr5.1使用的是1.9.6版本,于是通过三个solr的analyze功能分析要查询的地址:
两个使用jcseg2.6.0的solr6.2:
image.png
使用jcseg1.9.6的solr5.1:
image.png
两个结果比较了下,感觉还是1.9.6版本的英文分词结果更友好,2.6.0版本分词分的太细致了,将本应该在一起的单词也给拆分的七零八落了。
于是根据jcseg1.9.6的默认配置去修改jcseg2.6.0的分词器配置,最终修改后的jcseg-core-2.6.0.jar分词器中的配置文件jcseg.properties内容为:

# Jcseg properties file.
# @Note: 
# true | 1 | on for open the specified configuration or
# false | 0 | off to close it.
# bug report chenxin <chenxin619315@gmail.com>

# Jcseg function
#maximum match length. (5-7)
jcseg.maxlen = 5

#Whether to recognized the Chinese name.
jcseg.icnname = true

#maximum chinese word number of english chinese mixed word. 
jcseg.mixcnlen = 3

#maximum length for pair punctuation text.
jcseg.pptmaxlen = 7

#maximum length for Chinese last name andron.
jcseg.cnmaxlnadron = 1

#Whether to clear the stopwords.
jcseg.clearstopword = false

#Whether to convert the Chinese numeric to Arabic number. like '\u4E09\u4E07' to 30000.
jcseg.cnnumtoarabic = true

#Whether to convert the Chinese fraction to Arabic fraction.
#@Note: for lucene,solr,elasticsearch eg.. close it.
jcseg.cnfratoarabic = false

#Whether to keep the unrecognized word.
jcseg.keepunregword = true

#Whether to do the secondary segmentation for the complex English words
jcseg.ensecondseg = true

#min length of the secondary simple token. (better larger than 1)
jcseg.stokenminlen = 2

#minimum length of the secondary segmentation token.
jcseg.ensecminlen = 1

#Whether to do the English word segmentation
#the jcseg.ensecondseg must set to true before active this function
jcseg.enwordseg = false

#maximum match length for English extracted word
jcseg.enmaxlen = 16

#threshold for Chinese name recognize.
# better not change it before you know what you are doing.
jcseg.nsthreshold = 1000000

#The punctuation set that will be keep in an token.(Not the end of the token).
jcseg.keeppunctuations = @#%.&+

#Whether to append the pinyin of the entry.
jcseg.appendpinyin = false

#Whether to load and append the synonyms words of the entry.
jcseg.appendsyn = true


####for Tokenizer
#default delimiter for JcsegDelimiter tokenizer
#set to default or whitespace will use the default whitespace as delimiter
#or set to the char you want, like ',' or whatever
jcseg.delimiter = default

#default length for the N-gram tokenizer
jcseg.gram = 1


####about the lexicon
#absolute path of the lexicon file.
#Multiple path support from jcseg 1.9.2, use ';' to split different path.
#example: lexicon.path = /home/chenxin/lex1;/home/chenxin/lex2 (Linux)
#        : lexicon.path = D:/jcseg/lexicon/1;D:/jcseg/lexicon/2 (WinNT)
#lexicon.path=/Code/java/JavaSE/jcseg/lexicon
#lexicon.path = {jar.dir}/lexicon ({jar.dir} means the base directory of jcseg-core-{version}.jar)
#@since 1.9.9 Jcseg default to load the lexicons in the classpath
lexicon.path = {jar.dir}/lexicon

#Whether to load the modified lexicon file auto.
lexicon.autoload = true

#Poll time for auto load. (seconds)
lexicon.polltime = 30


####lexicon load
#Whether to load the part of speech of the entry.
jcseg.loadpos = true

#Whether to load the pinyin of the entry.
jcseg.loadpinyin = false

#Whether to load the synonyms words of the entry.
jcseg.loadsyn = true

#Whether to load the entity of the entry
jcseg.loadentity = true

修改后的jcseg分词器分词效果如下:
image.png
已经与jcseg1.9.6分词效果基本一致了,这时候两个solr6.2.0再重做索引,再次执行之前的查询,发现检索得分还是100多分。

2、问题原因是否由于solr6和5默认相似性算法不一致导致

根据上面实验,于是这里怀疑不只是因为分词器分词差异导致的问题,更大的问题应该在于solr5和solr6的相似度得分算法不一样了,为了排除分词器带来的影响,于是将solr6.2使用的分词器也替换成solr5.1使用那一套分词器,再次索引同样的数据,做同样的查询发现得分还是很高,那就说明相似得分差异过大的主要原因是由于solr两个版本的算法不一致导致的了。
经过网上查找资料发现了solr5和solr6的默认相似度算法的确是变了:

默认的相似性改变

当 Schema 没有明确地定义全局 \<similarity/> 时,Solr 的默认行为将依赖于 solrconfig. xml 中指定的
luceneMatchVersion。当 luceneMatchVersion < 6.0 时,将使用
ClassicSimilarityFactory 的实例,否则将使用 SchemaSimilarityFactory
的实例。最值得注意的是,这种改变意味着用户可以利用每个字段类型的相似性声明,并且需要明确声明 SchemaSimilarityFactory
的全局用法。 无论是明确声明还是作为隐式全局默认值使用,当字段类型不声明明确\<similarity/>
时,SchemaSimilarityFactory 的隐式行为也被更改为依赖于 luceneMatchVersion。当
luceneMatchVersion < 6.0 时,将使用 ClassicSimilarity 的实例,否则将使用
BM25Similarity 的实例。可以在 SchemaSimilarityFactory 声明中指定
defaultSimFromFieldType init 选项来更改此行为。请查看
SchemaSimilarityFactoryjavadocs 了解更多详情

于是修改solr6.2的manage-schema,新增similarity显示指定:

<similarity class="solr.ClassicSimilarityFactory"/>

而且由于当前环境索引速度较慢,同时修改solrconfig.xml的索引并行度:

<maxIndexingThreads>32</maxIndexingThreads>

重启solr,重做索引,发现现在索引速度比原来快了一个小时,再次做同样的查询,检索得分已经同solr5.1相似了:
image.png

相关实践学习
基于MaxCompute的热门话题分析
Apsara Clouder大数据专项技能认证配套课程:基于MaxCompute的热门话题分析
相关文章
|
3月前
|
存储 分布式计算 大数据
基于Python大数据的的电商用户行为分析系统
本系统基于Django、Scrapy与Hadoop技术,构建电商用户行为分析平台。通过爬取与处理海量用户数据,实现行为追踪、偏好分析与个性化推荐,助力企业提升营销精准度与用户体验,推动电商智能化发展。
|
4月前
|
数据可视化 搜索推荐 大数据
基于python大数据的北京旅游可视化及分析系统
本文深入探讨智慧旅游系统的背景、意义及研究现状,分析其在旅游业中的作用与发展潜力,介绍平台架构、技术创新、数据挖掘与服务优化等核心内容,并展示系统实现界面。
|
5月前
|
数据采集 人工智能 分布式计算
ODPS在AI时代的发展战略与技术演进分析报告
ODPS(现MaxCompute)历经十五年发展,从分布式计算平台演进为AI时代的数据基础设施,以超大规模处理、多模态融合与Data+AI协同为核心竞争力,支撑大模型训练与实时分析等前沿场景,助力企业实现数据驱动与智能化转型。
439 4
|
4月前
|
机器学习/深度学习 自然语言处理 算法
大数据选举预测:算票的不只是选票,还有算法
大数据选举预测:算票的不只是选票,还有算法
193 0
|
5月前
|
JSON 大数据 API
巧用苏宁易购 API,精准分析苏宁易购家电销售大数据
在数据驱动的电商时代,精准分析销售数据能助力企业优化库存、提升营销效果。本文详解如何利用苏宁易购API获取家电销售数据,结合Python进行数据清洗与统计分析,实现销量预测与洞察提取,帮助企业降本增效。
152 0
|
6月前
|
消息中间件 NoSQL 数据可视化
数据说了算,可你得“听得快”——聊聊大数据里的实时分析
数据说了算,可你得“听得快”——聊聊大数据里的实时分析
169 2
|
4月前
|
存储 SQL 分布式计算
终于!大数据分析不用再“又要快又要省钱”二选一了!Dataphin新功能太香了!
Dataphin推出查询加速新功能,支持用StarRocks等引擎直连MaxCompute或Hadoop查原始数据,无需同步、秒级响应。数据只存一份,省成本、提效率,权限统一管理,打破“又要快又要省”的不可能三角,助力企业实现分析自由。
251 49
|
3月前
|
算法 搜索推荐 大数据
当“爆款书”遇上大数据:出版业的老路,正在被算法改写
当“爆款书”遇上大数据:出版业的老路,正在被算法改写
204 8