网站设计结果,泸州市住房和城乡建设厅官方网站,免费品牌网站制作,it网站开发想要提高召回率就需要尽可能匹配相关的文档#xff0c;其中一个办法就是在索引阶段对词语分析#xff08;分词器#xff09;的时候提取词干#xff0c;搜索的时候也取词干。
不取词干
es默认使用的是标准的分词器#xff0c;是不会取词干的。 但是标准分词器是包含小写转…想要提高召回率就需要尽可能匹配相关的文档其中一个办法就是在索引阶段对词语分析分词器的时候提取词干搜索的时候也取词干。
不取词干
es默认使用的是标准的分词器是不会取词干的。 但是标准分词器是包含小写转换分词过滤器的也是可以提高召回率的。
{analyzer: standard,text: I liked apple
}{tokens: [{token: i,start_offset: 0,end_offset: 1,type: ALPHANUM,position: 0},{token: liked,start_offset: 2,end_offset: 7,type: ALPHANUM,position: 1},{token: apple,start_offset: 8,end_offset: 13,type: ALPHANUM,position: 2}]
}【liked】被分词器切割出来了
那我们使用【liked】进行搜索是能搜索出来的但是如果我们使用【like】是无法搜索出来的。
那为了提高召回率我们需要对【liked】二次提取提取出词干【like】那么搜索的时候无论是使用like、liked、liking都能搜索出来了
取词干
使用能取词干的分词器比如english
{analyzer: english,text: I liked apple
}{tokens: [{token: i,start_offset: 0,end_offset: 1,type: ALPHANUM,position: 0},{token: like,start_offset: 2,end_offset: 7,type: ALPHANUM,position: 1},{token: appl,start_offset: 8,end_offset: 13,type: ALPHANUM,position: 2}]
}【liked】提取出来的词干是【like】
取词干带来的准确率问题
问题描述
如果用户就是想根据时态过去式、过去分词搜索返回的数据会和用户预料的一样么 比如现在有两条数据
{id:1,content:I like apple}
{id:2,content:I liked apple}现在搜索词是【liked】那么两条数据都会被搜出来并且评分一样如下
{query:{match:{content:i liked it}}
}{took: 1,timed_out: false,_shards: {total: 1,successful: 1,skipped: 0,failed: 0},hits: {total: {value: 2,relation: eq},max_score: 0.18232156,hits: [{_index: dong_analyzer_test,_type: _doc,_id: 1,_score: 0.18232156,_source: {id: 1,content: I like apple}},{_index: dong_analyzer_test,_type: _doc,_id: 2,_score: 0.18232156,_source: {id: 2,content: I liked apple}}]}
}可以发现文档2排在了第二位如果数量多一点可能页面第一页都看不到他但实际上他应该排在第一位
解决办法
再加一个字段
{properties: {content: {type: text,analyzer: english,fields: {std: {type: text,analyzer: standard}}}}
}content使用了提取词干的分词器content.std不使用标准分词器
注意如果是新增字段需要重新导入一遍数据。
搜索的时候进行多字段搜索
{query: {multi_match: {query: I liked it,type: most_fields, fields: [ content, content.std ]}}
}most_fields是将两个字段查询的评分加起来
{took: 1,timed_out: false,_shards: {total: 1,successful: 1,skipped: 0,failed: 0},hits: {total: {value: 2,relation: eq},max_score: 1.2401118,hits: [{_index: dong_analyzer_test,_type: _doc,_id: 2,_score: 1.2401118,_source: {id: 2,content: I liked apple}},{_index: dong_analyzer_test,_type: _doc,_id: 1,_score: 0.5469647,_source: {id: 1,content: I like apple}}]}
}