Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix for issue 662 #835

Open
wants to merge 1 commit into
base: 6.x
Choose a base branch
from
Open

bug fix for issue 662 #835

wants to merge 1 commit into from

Conversation

yanghanxy
Copy link

@yanghanxy yanghanxy commented Nov 19, 2020

AnalyzeContext.result 从 LinkedList 改成 TreeSet,修复 issue 662 问题:#662

用这三个 case 复现了一下问题:

  1. 得饶人处且饶人
  2. 黎明前的黑暗
  3. 宝剑锋从磨砺出

ik_max 分词结果:

  1. [0-7 : 得饶人处且饶人 : CN_WORD, 0-4 : 得饶人处 : CN_WORD, 1-3 : 饶人 : CN_WORD, 4-5 : 且 : CN_CHAR, 3-4 : 处 : CN_CHAR, 4-5 : 且 : CN_CHAR, 5-7 : 饶人 : CN_WORD]
  2. [0-6 : 黎明前的黑暗 : CN_WORD, 0-3 : 黎明前 : CN_WORD, 0-2 : 黎明 : CN_WORD, 3-4 : 的 : CN_CHAR, 2-3 : 前 : CN_CHAR, 3-4 : 的 : CN_CHAR, 4-6 : 黑暗 : CN_WORD]
  3. [0-7 : 宝剑锋从磨砺出 : CN_WORD, 0-3 : 宝剑锋 : CN_WORD, 0-2 : 宝剑 : CN_WORD, 3-4 : 从 : CN_CHAR, 2-3 : 锋 : CN_CHAR, 3-4 : 从 : CN_CHAR, 4-6 : 磨砺 : CN_WORD, 6-7 : 出 : CN_CHAR]

问题表现:
输出的 Lexeme 并不是按 offset 顺序输出的,如下:

  1. [4-5 : 且 : CN_CHAR, 3-4 : 处 : CN_CHAR, 4-5 : 且 : CN_CHAR]
  2. [3-4 : 的 : CN_CHAR, 2-3 : 前 : CN_CHAR, 3-4 : 的 : CN_CHAR]
  3. [3-4 : 从 : CN_CHAR, 2-3 : 锋 : CN_CHAR, 3-4 : 从 : CN_CHAR]

问题来源:
这个 commit 在 AnalyzeContext 中新增的 “切分前一个冲突词元的单字” 方法,与 AnalyzeContext 中原本的单字逻辑 “输出path内部,词元间遗漏的单字” 有冲突。某些情况下(如上述三个例子),前者输出的单字,会在后者中重复输出,并且引入顺序问题,造成 ES 索引报错。

解决方法:
AnalyzeContext 的 result 从 LinkedList 改成 TreeSet,避免重复添加,并保证结果按序输出。

修复后结果:

  1. [0-7 : 得饶人处且饶人 : CN_WORD, 0-4 : 得饶人处 : CN_WORD, 1-3 : 饶人 : CN_WORD, 3-4 : 处 : CN_CHAR, 4-5 : 且 : CN_CHAR, 5-7 : 饶人 : CN_WORD]
  2. [0-6 : 黎明前的黑暗 : CN_WORD, 0-3 : 黎明前 : CN_WORD, 0-2 : 黎明 : CN_WORD, 2-3 : 前 : CN_CHAR, 3-4 : 的 : CN_CHAR, 4-6 : 黑暗 : CN_WORD]
  3. [0-7 : 宝剑锋从磨砺出 : CN_WORD, 0-3 : 宝剑锋 : CN_WORD, 0-2 : 宝剑 : CN_WORD, 2-3 : 锋 : CN_CHAR, 3-4 : 从 : CN_CHAR, 4-6 : 磨砺 : CN_WORD, 6-7 : 出 : CN_CHAR]

this.result 从 LinkedList 改成 TreeSet,修复 issue 662 问题,
infinilabs#662
@yanghanxy
Copy link
Author

@medcl 帮忙评估一下这个pr的合理性哈,

我看到 master branch 是通过这个commit,以注释代码的方式修复了issue 662

如果感觉我提的pr方案不是很好的话,建议可以直接把master的修复合并到6.X branch上,避免其他用6.X的同学踩坑哈。

lxw-mesoor pushed a commit to nadileaf/elasticsearch-analysis-ik that referenced this pull request Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant