【发布时间】:2013-07-02 20:04:05
【问题描述】:
我写了一个TokenFilter 在流中添加标记。
1。测试表明它有效,但我不完全明白为什么。
如果有人能阐明语义,我将不胜感激。特别是在(*),恢复状态,是不是意味着我们要么覆盖当前的token,要么覆盖在捕获状态之前创建的token?
这大概就是我所做的
private final LinkedList<String> extraTokens = new LinkedList<String>();
private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
private State savedState;
@Override
public boolean incrementToken() throws IOException {
if (!extraTokens.isEmpty()) {
// Do we not loose/overwrite the current termAtt token here? (*)
restoreState(savedState);
termAtt.setEmpty().append(extraTokens.remove());
return true;
}
if (input.incrementToken()) {
if (/* condition */) {
extraTokens.add("fo");
savedState = captureState();
}
return true;
}
return false;
}
这是否意味着,对于空格标记化字符串 "a b c" 的输入流
(a) -> (b) -> (c) -> ...
其中bb 是b 的新同义词,当使用restoreState 时,图将这样构造?
(a)
/ \
(b) (bb)
\ /
(c)
|
...
2。属性
鉴于文本foo bar baz 与fo 是foo 的词干和qux 是bar baz 的同义词,我是否构建了正确的属性表?
+--------+---------------+-----------+--------------+-----------+
| Term | startOffset | endOffset | posIncrement | posLenght |
+--------+---------------+-----------+--------------+-----------+
| foo | 0 | 3 | 1 | 1 |
| fo | 0 | 3 | 0 | 1 |
| qux | 4 | 11 | 0 | 2 |
| bar | 4 | 7 | 1 | 1 |
| baz | 8 | 11 | 1 | 1 |
+--------+---------------+-----------+--------------+-----------+
【问题讨论】:
-
答案是:是的!!! :-) :-)
标签: java solr lucene token solr4