2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 using TermAttribute = Mono.Lucene.Net.Analysis.Tokenattributes.TermAttribute;
22 namespace Mono.Lucene.Net.Analysis
25 /// <summary> Removes words that are too long or too short from the stream.
29 /// <version> $Id: LengthFilter.java 807201 2009-08-24 13:22:34Z markrmiller $
31 public sealed class LengthFilter:TokenFilter
37 private TermAttribute termAtt;
39 /// <summary> Build a filter that removes words that are too long or too
40 /// short from the text.
42 public LengthFilter(TokenStream in_Renamed, int min, int max):base(in_Renamed)
46 termAtt = (TermAttribute) AddAttribute(typeof(TermAttribute));
49 /// <summary> Returns the next input Token whose term() is the right len</summary>
50 public override bool IncrementToken()
52 // return the first non-stop word found
53 while (input.IncrementToken())
55 int len = termAtt.TermLength();
56 if (len >= min && len <= max)
60 // note: else we ignore it but should we index each part of it?
62 // reached EOS -- return null