沙师弟,师父的充电器掉了

分词的posiiton为什么不连续,为什么和原始的词的位置不一样,求解

Elasticsearch | 作者 wmj | 发布于2017年03月30日 | 阅读数:3322

例如:我在漫步人生,分词为:

{
"tokens": [
{
"token": "w",
"start_offset": 0,
"end_offset": 1,
"type": "word",
"position": 0
},
{
"token": "wo",
"start_offset": 0,
"end_offset": 1,
"type": "word",
"position": 1
},
{
"token": "z",
"start_offset": 1,
"end_offset": 2,
"type": "word",
"position": 2
},
{
"token": "zai",
"start_offset": 1,
"end_offset": 2,
"type": "word",
"position": 3
},
{
"token": "m",
"start_offset": 2,
"end_offset": 3,
"type": "word",
"position": 4
},
{
"token": "man",
"start_offset": 2,
"end_offset": 3,
"type": "word",
"position": 5
},
{
"token": "b",
"start_offset": 3,
"end_offset": 4,
"type": "word",
"position": 6
},
{
"token": "bu",
"start_offset": 3,
"end_offset": 4,
"type": "word",
"position": 7
},
{
"token": "r",
"start_offset": 4,
"end_offset": 5,
"type": "word",
"position": 8
},
{
"token": "ren",
"start_offset": 4,
"end_offset": 5,
"type": "word",
"position": 9
},
{
"token": "s",
"start_offset": 5,
"end_offset": 6,
"type": "word",
"position": 10
},
{
"token": "sheng",
"start_offset": 5,
"end_offset": 6,
"type": "word",
"position": 11
},
{
"token": "wozaimanburensheng",
"start_offset": 0,
"end_offset": 18,
"type": "word",
"position": 12
},
{
"token": "wzmbrs",
"start_offset": 0,
"end_offset": 6,
"type": "word",
"position": 13
}
]
}

问题1:

如果我进行短语搜索不能匹配 “wozaiman” ,需要写成:“wwozzaimman”。

问题2:

理想中的位置:
w,z,,m应该是0,1,2

wo,zai,man也是0,1,2

wozaimanbu是0,

wzmb是0.

能解析一下为什么不是这样吗,谢谢大神。

我不希望把wozaiman 索引成 w,z,m,我希望保留原来的,wo,zai,man,这样不会丢失精度。同时我也希望搜搜wozmbu也能匹配,如果对应的term的位置一致,应该就可以实现吧
已邀请:

kepmoving - 90后

赞同来自:

短语匹配的时候加上slop间距,应该可以实现你的需求
 
我不希望把wozaiman 索引成 w,z,m,我希望保留原来的,wo,zai,man,这样不会丢失精度。同时我也希望搜搜wozmbu也能匹配,如果对应的term的位置一致,应该就可以实现吧
分词的时候不切分出首字母,那你这个wozmbu怎么匹配?

kennywu76 - Wood

赞同来自:

拼音分词器有很多选项控制分词的时候保留哪些部分, 你可以通过参数组合,索引多个字段,比如有的字段只保留首字母,有的字段保留全拼,然后查询的时候通过bool query做组合查询。 

wmj

赞同来自:

当位置不对,短语搜索就不对,我希望严格控制位置,还有一个问题offset不对要导致高亮出错。我在使用的时候会遇到高亮出错和短语的问题。

要回复问题请先登录注册