cvsimport
[beagle.git] / beagled / Lucene.Net / Analysis / LengthFilter.cs
blobcba425dee00c7bc50dd6262c18526b194e46cbc5
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System;
19 namespace Lucene.Net.Analysis
22 /// <summary> Removes words that are too long and too short from the stream.
23 ///
24 /// </summary>
25 /// <author> David Spencer
26 /// </author>
27 /// <version> $Id: LengthFilter.cs,v 1.2 2006/10/02 17:08:47 joeshaw Exp $
28 /// </version>
29 public sealed class LengthFilter : TokenFilter
32 internal int min;
33 internal int max;
35 /// <summary> Build a filter that removes words that are too long or too
36 /// short from the text.
37 /// </summary>
38 public LengthFilter(TokenStream in_Renamed, int min, int max) : base(in_Renamed)
40 this.min = min;
41 this.max = max;
44 /// <summary> Returns the next input Token whose termText() is the right len</summary>
45 public override Token Next()
47 // return the first non-stop word found
48 for (Token token = input.Next(); token != null; token = input.Next())
50 int len = token.TermText().Length;
51 if (len >= min && len <= max)
53 return token;
55 // note: else we ignore it but should we index each part of it?
57 // reached EOS -- return null
58 return null;