我正在尝试编写一个Lucene过滤器,用“what is "替换”what 's",用“cannot”替换“can 't”等术语。
在incrementToken()
中,如果term是我要替换的字符串之一,我计算一个替换字符串(例如what 's-〉what is),并将其推送到CharTermAttribute:termAttr.copyBuffer(replacement.toCharArray, 0, replacement.length)
个
但这似乎并不起作用,当我搜索“what 's”时,我仍然得到包含“what' s”的结果,而不是被视为“what is”的字符串。
实现这一点的正确方法是什么?我需要创建一个tokenizer吗?(理想情况下,我希望保留StandardTokenizer并添加到它,而不是替换它)
1条答案
按热度按时间4si2a6ki1#
这可以通过使用标记化器而不是过滤器来解决。