FileDocCategorySizeDatePackage
LengthFilter.javaAPI DocApache Lucene 1.91669Mon Feb 20 09:19:46 GMT 2006org.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 347992 2005-11-21 21:41:43Z dnaber $

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;