List of usage examples for org.apache.lucene.analysis TokenStream captureState
public final State captureState()
From source file:org.apache.uima.lucas.indexer.analysis.TokenStreamMerger.java
License:Apache License
@Override public boolean incrementToken() throws IOException { if (!initialized) init();/* ww w.j a va 2 s . c om*/ if (sortedStreams.size() == 0) return false; TokenStream currentTokenStream = sortedStreams.pop(); restoreState(currentTokenStream.captureState()); OffsetAttribute offsetAttr = (OffsetAttribute) currentTokenStream.getAttribute(OffsetAttribute.class); if (offsetAttr.startOffset() == currentOffset) posIncAtt.setPositionIncrement(0); else posIncAtt.setPositionIncrement(1); currentOffset = offsetAttr.startOffset(); // proceed the token stream to its next token and resort the stack if (currentTokenStream.incrementToken()) sortedStreams.add(currentTokenStream); rebuildSortedTokens(); return true; }
From source file:org.gridkit.coherence.search.lucene.CapturedTokenStream.java
License:Apache License
public void append(TokenStream ts, int positionGap, int offsetShift) throws IOException { PositionIncrementAttribute pi = null; pi = ts.getAttribute(PositionIncrementAttribute.class); OffsetAttribute off = null;//from w w w .j a v a 2 s .c o m if (offsetShift != 0) { off = ts.getAttribute(OffsetAttribute.class); } ts.reset(); while (ts.incrementToken()) { if (positionGap != 0) { pi.setPositionIncrement(positionGap); positionGap = 0; } if (off != null) { off.setOffset(offsetShift + off.startOffset(), offsetShift + off.endOffset()); } tokens.add(ts.captureState()); lastPos += pi.getPositionIncrement(); } }