QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / beagled / Lucene.Net / Search / FilteredTermEnum.cs
blob31a6ec44c954f06fe44e29cea14532fae2392494
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;
18 using Term = Lucene.Net.Index.Term;
19 using TermEnum = Lucene.Net.Index.TermEnum;
21 namespace Lucene.Net.Search
24 /// <summary>Abstract class for enumerating a subset of all terms.
25 /// <p>Term enumerations are always ordered by Term.compareTo(). Each term in
26 /// the enumeration is greater than all that precede it.
27 /// </summary>
28 public abstract class FilteredTermEnum:TermEnum
30 private Term currentTerm = null;
31 private TermEnum actualEnum = null;
33 public FilteredTermEnum()
37 /// <summary>Equality compare on the term </summary>
38 protected internal abstract bool TermCompare(Term term);
40 /// <summary>Equality measure on the term </summary>
41 public abstract float Difference();
43 /// <summary>Indiciates the end of the enumeration has been reached </summary>
44 public abstract bool EndEnum();
46 protected internal virtual void SetEnum(TermEnum actualEnum)
48 this.actualEnum = actualEnum;
49 // Find the first term that matches
50 Term term = actualEnum.Term();
51 if (term != null && TermCompare(term))
52 currentTerm = term;
53 else
54 Next();
57 /// <summary> Returns the docFreq of the current Term in the enumeration.
58 /// Returns -1 if no Term matches or all terms have been enumerated.
59 /// </summary>
60 public override int DocFreq()
62 if (actualEnum == null)
63 return - 1;
64 return actualEnum.DocFreq();
67 /// <summary>Increments the enumeration to the next element. True if one exists. </summary>
68 public override bool Next()
70 if (actualEnum == null)
71 return false; // the actual enumerator is not initialized!
72 currentTerm = null;
73 while (currentTerm == null)
75 if (EndEnum())
76 return false;
77 if (actualEnum.Next())
79 Term term = actualEnum.Term();
80 if (TermCompare(term))
82 currentTerm = term;
83 return true;
86 else
87 return false;
89 currentTerm = null;
90 return false;
93 /// <summary>Returns the current Term in the enumeration.
94 /// Returns null if no Term matches or all terms have been enumerated.
95 /// </summary>
96 public override Term Term()
98 return currentTerm;
101 /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
102 public override void Close()
104 actualEnum.Close();
105 currentTerm = null;
106 actualEnum = null;