Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / tools / monkeydoc / Lucene.Net / Lucene.Net / Analysis / LengthFilter.cs
1 /* 
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
8  * 
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  */
17
18 using System;
19
20 using TermAttribute = Mono.Lucene.Net.Analysis.Tokenattributes.TermAttribute;
21
22 namespace Mono.Lucene.Net.Analysis
23 {
24         
25         /// <summary> Removes words that are too long or too short from the stream.
26         /// 
27         /// 
28         /// </summary>
29         /// <version>  $Id: LengthFilter.java 807201 2009-08-24 13:22:34Z markrmiller $
30         /// </version>
31         public sealed class LengthFilter:TokenFilter
32         {
33                 
34                 internal int min;
35                 internal int max;
36                 
37                 private TermAttribute termAtt;
38                 
39                 /// <summary> Build a filter that removes words that are too long or too
40                 /// short from the text.
41                 /// </summary>
42                 public LengthFilter(TokenStream in_Renamed, int min, int max):base(in_Renamed)
43                 {
44                         this.min = min;
45                         this.max = max;
46                         termAtt = (TermAttribute) AddAttribute(typeof(TermAttribute));
47                 }
48                 
49                 /// <summary> Returns the next input Token whose term() is the right len</summary>
50                 public override bool IncrementToken()
51                 {
52                         // return the first non-stop word found
53                         while (input.IncrementToken())
54                         {
55                                 int len = termAtt.TermLength();
56                                 if (len >= min && len <= max)
57                                 {
58                                         return true;
59                                 }
60                                 // note: else we ignore it but should we index each part of it?
61                         }
62                         // reached EOS -- return null
63                         return false;
64                 }
65         }
66 }