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 Term = Mono.Lucene.Net.Index.Term;
21 using TermEnum = Mono.Lucene.Net.Index.TermEnum;
23 namespace Mono.Lucene.Net.Search
26 /// <summary>Abstract class for enumerating a subset of all terms.
27 /// <p/>Term enumerations are always ordered by Term.compareTo(). Each term in
28 /// the enumeration is greater than all that precede it.
30 public abstract class FilteredTermEnum:TermEnum
32 /// <summary>the current term </summary>
33 protected internal Term currentTerm = null;
35 /// <summary>the delegate enum - to set this member use {@link #setEnum} </summary>
36 protected internal TermEnum actualEnum = null;
38 public FilteredTermEnum()
42 /// <summary>Equality compare on the term </summary>
43 public /*protected internal*/ abstract bool TermCompare(Term term);
45 /// <summary>Equality measure on the term </summary>
46 public abstract float Difference();
48 /// <summary>Indicates the end of the enumeration has been reached </summary>
49 public abstract bool EndEnum();
51 /// <summary> use this method to set the actual TermEnum (e.g. in ctor),
52 /// it will be automatically positioned on the first matching term.
54 protected internal virtual void SetEnum(TermEnum actualEnum)
56 this.actualEnum = actualEnum;
57 // Find the first term that matches
58 Term term = actualEnum.Term();
59 if (term != null && TermCompare(term))
65 /// <summary> Returns the docFreq of the current Term in the enumeration.
66 /// Returns -1 if no Term matches or all terms have been enumerated.
68 public override int DocFreq()
70 if (currentTerm == null)
72 System.Diagnostics.Debug.Assert(actualEnum != null);
73 return actualEnum.DocFreq();
76 /// <summary>Increments the enumeration to the next element. True if one exists. </summary>
77 public override bool Next()
79 if (actualEnum == null)
80 return false; // the actual enumerator is not initialized!
82 while (currentTerm == null)
86 if (actualEnum.Next())
88 Term term = actualEnum.Term();
89 if (TermCompare(term))
102 /// <summary>Returns the current Term in the enumeration.
103 /// Returns null if no Term matches or all terms have been enumerated.
105 public override Term Term()
110 /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
111 public override void Close()
113 if (actualEnum != null)