Lucene无法多次迭代TokenStream

时间:2017-02-09 09:22:42

标签: lucene

我正在尝试在我的自定义过滤器中多次迭代TokenStream。

   @Override
   public boolean incrementToken() throws IOException {
      if (first) {
         while (input.incrementToken()) {
            System.out.println(
                  "[" + input.getAttribute(CharTermAttribute.class).toString() +
                        ", " + offsetAttribute.startOffset() +
                        ", " + offsetAttribute.endOffset() +
                        "," + positionIncrementAttribute.getPositionIncrement() +
                        "] "
            );
         }
         first = false;
         super.reset();
         return true;
      }
      if (!this.input.incrementToken()) {
         return false;
      }
      this.charTermAttribute.setEmpty().append(input.getAttribute(CharTermAttribute.class).toString());
      this.positionIncrementAttribute.setPositionIncrement(1);
      return true;
   }

我需要将所有令牌放在列表中(我只是暂时显示它们)然后根据基于此列表的逻辑修改我的令牌。

这是输出:

[125, 0, 3,1] 
[RUE, 5, 8,1] 
[DE, 9, 11,1] 
[LA, 12, 14,1] 
[REPUBLIQUE, 15, 25,1] 
[souffre, 27, 34,1] 
[de, 35, 37,1] 
[LA, 38, 40,1] 

java.lang.IllegalStateException: TokenStream contract violation: reset()/close() call missing, reset() called multiple times, or subclass does not call super.reset(). Please see Javadocs of TokenStream class for more information about the correct consuming workflow.

请问好吗?

Lucene 4.7.2

0 个答案:

没有答案