FileDocCategorySizeDatePackage
LengthFilter.javaAPI DocApache Lucene 2.1.01856Wed Feb 14 10:46:38 GMT 2007org.apache.lucene.analysis

LengthFilter

public final class LengthFilter extends TokenFilter
Removes words that are too long and too short from the stream.
author
David Spencer
version
$Id: LengthFilter.java 472959 2006-11-09 16:21:50Z yonik $

Fields Summary
final int
min
final int
max
Constructors Summary
public LengthFilter(TokenStream in, int min, int max)
Build a filter that removes words that are too long or too short from the text.

    super(in);
    this.min = min;
    this.max = max;
  
Methods Summary
public final org.apache.lucene.analysis.Tokennext()
Returns the next input Token whose termText() is the right len

    // return the first non-stop word found
    for (Token token = input.next(); token != null; token = input.next())
    {
      int len = token.termText().length();
      if (len >= min && len <= max) {
          return token;
      }
      // note: else we ignore it but should we index each part of it?
    }
    // reached EOS -- return null
    return null;