lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From KingShooter <>
Subject How to implement a GivenCharFilter using incrementToken
Date Wed, 25 Nov 2009 04:15:30 GMT

    I find it is very hard to implement a GivenCharFilter(extends
TokenFilter)using incrementToken. My requirment is like this: I want to
analyze a StringReader("axb xxa xx c") to these token[term(startOffset,
endOffset, posIncre)]:
a(0,1,1) b(2,3,1) a(4,5,1) c(6,7,1).
    First I use a WhiteSpaceFilter to filter the token, and then use
GivenCharFilter( assume filter "x" like above). the problem is: when call
incrementToken, I get attributeTerm "axb", but this time I need return two
attribute terms "a" and "b", but how to? because it just return only one
   Please help me.

My code just like this:


public class GivenCharFilter extends TokenFilter{

  private char filterChar='x';
  private TermAttribute termAtt;
  private OffsetAttribute offsetAtt;
  private PositionIncrementAttribute posIncrAtt;

  public GivenCharFilter(){

  public void init() {	
        termAtt = (TermAttribute) addAttribute(TermAttribute.class);
        offsetAtt = (OffsetAttribute) addAttribute(OffsetAttribute.class);
        posIncrAtt = (PositionIncrementAttribute)

  /** Returns the next token in the stream, or null at EOS. */
  public final boolean incrementToken() throws IOException {
      //How To?


Xiaotao Deng
View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message