2 * Copyright 2004 The Apache Software Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 IndexInput
= Lucene
.Net
.Store
.IndexInput
;
18 namespace Lucene
.Net
.Index
21 sealed public class SegmentTermEnum
: TermEnum
, System
.ICloneable
23 private IndexInput input
;
24 internal FieldInfos fieldInfos
;
26 internal long position
= - 1;
28 private TermBuffer termBuffer
= new TermBuffer();
29 private TermBuffer prevBuffer
= new TermBuffer();
30 private TermBuffer scratch
; // used for scanning
32 private TermInfo termInfo
= new TermInfo();
35 private bool isIndex
= false;
36 internal long indexPointer
= 0;
37 internal int indexInterval
;
38 internal int skipInterval
;
39 private int formatM1SkipInterval
;
41 internal SegmentTermEnum(IndexInput i
, FieldInfos fis
, bool isi
)
47 int firstInt
= input
.ReadInt();
50 // original-format file, without explicit format version number
54 // back-compatible settings
56 skipInterval
= System
.Int32
.MaxValue
; // switch off skipTo optimization
60 // we have a format version number
63 // check that it is a format we can understand
64 if (format
< TermInfosWriter
.FORMAT
)
65 throw new System
.IO
.IOException("Unknown format version:" + format
);
67 size
= input
.ReadLong(); // read the size
73 indexInterval
= input
.ReadInt();
74 formatM1SkipInterval
= input
.ReadInt();
76 // switch off skipTo optimization for file format prior to 1.4rc2 in order to avoid a bug in
77 // skipTo implementation of these versions
78 skipInterval
= System
.Int32
.MaxValue
;
82 indexInterval
= input
.ReadInt();
83 skipInterval
= input
.ReadInt();
88 public System
.Object
Clone()
90 SegmentTermEnum clone
= null;
93 clone
= (SegmentTermEnum
) base.MemberwiseClone();
95 catch (System
.Exception
)
99 clone
.input
= (IndexInput
) input
.Clone();
100 clone
.termInfo
= new TermInfo(termInfo
);
102 clone
.termBuffer
= (TermBuffer
) termBuffer
.Clone();
103 clone
.prevBuffer
= (TermBuffer
) prevBuffer
.Clone();
104 clone
.scratch
= null;
109 internal void Seek(long pointer
, int p
, Term t
, TermInfo ti
)
118 /// <summary>Increments the enumeration to the next element. True if one exists.</summary>
119 public override bool Next()
121 if (position
++ >= size
- 1)
127 prevBuffer
.Set(termBuffer
);
128 termBuffer
.Read(input
, fieldInfos
);
130 termInfo
.docFreq
= input
.ReadVInt(); // read doc freq
131 termInfo
.freqPointer
+= input
.ReadVLong(); // read freq pointer
132 termInfo
.proxPointer
+= input
.ReadVLong(); // read prox pointer
136 // just read skipOffset in order to increment file pointer;
137 // value is never used since skipTo is switched off
140 if (termInfo
.docFreq
> formatM1SkipInterval
)
142 termInfo
.skipOffset
= input
.ReadVInt();
148 if (termInfo
.docFreq
>= skipInterval
)
149 termInfo
.skipOffset
= input
.ReadVInt();
153 indexPointer
+= input
.ReadVLong(); // read index pointer
158 /// <summary>Optimized scan, without allocating new terms. </summary>
159 internal void ScanTo(Term term
)
162 scratch
= new TermBuffer();
164 while (scratch
.CompareTo(termBuffer
) > 0 && Next())
169 /// <summary>Returns the current Term in the enumeration.
170 /// Initially invalid, valid after next() called for the first time.
172 public override Term
Term()
174 return termBuffer
.ToTerm();
177 /// <summary>Returns the previous Term enumerated. Initially null.</summary>
180 return prevBuffer
.ToTerm();
183 /// <summary>Returns the current TermInfo in the enumeration.
184 /// Initially invalid, valid after next() called for the first time.
186 internal TermInfo
TermInfo()
188 return new TermInfo(termInfo
);
191 /// <summary>Sets the argument to the current TermInfo in the enumeration.
192 /// Initially invalid, valid after next() called for the first time.
194 internal void TermInfo(TermInfo ti
)
199 /// <summary>Returns the docFreq from the current TermInfo in the enumeration.
200 /// Initially invalid, valid after next() called for the first time.
202 public override int DocFreq()
204 return termInfo
.docFreq
;
207 /* Returns the freqPointer from the current TermInfo in the enumeration.
208 Initially invalid, valid after next() called for the first time.*/
209 internal long FreqPointer()
211 return termInfo
.freqPointer
;
214 /* Returns the proxPointer from the current TermInfo in the enumeration.
215 Initially invalid, valid after next() called for the first time.*/
216 internal long ProxPointer()
218 return termInfo
.proxPointer
;
221 /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
222 public override void Close()