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.
18 using IndexInput
= Lucene
.Net
.Store
.IndexInput
;
20 namespace Lucene
.Net
.Index
23 public sealed class SegmentTermEnum
: TermEnum
, System
.ICloneable
25 private IndexInput input
;
26 internal FieldInfos fieldInfos
;
28 internal long position
= - 1;
30 private TermBuffer termBuffer
= new TermBuffer();
31 private TermBuffer prevBuffer
= new TermBuffer();
32 private TermBuffer scratch
; // used for scanning
34 private TermInfo termInfo
= new TermInfo();
37 private bool isIndex
= false;
38 internal long indexPointer
= 0;
39 internal int indexInterval
;
40 internal int skipInterval
;
41 private int formatM1SkipInterval
;
43 internal SegmentTermEnum(IndexInput i
, FieldInfos fis
, bool isi
)
49 int firstInt
= input
.ReadInt();
52 // original-format file, without explicit format version number
56 // back-compatible settings
58 skipInterval
= System
.Int32
.MaxValue
; // switch off skipTo optimization
62 // we have a format version number
65 // check that it is a format we can understand
66 if (format
< TermInfosWriter
.FORMAT
)
67 throw new System
.IO
.IOException("Unknown format version:" + format
);
69 size
= input
.ReadLong(); // read the size
75 indexInterval
= input
.ReadInt();
76 formatM1SkipInterval
= input
.ReadInt();
78 // switch off skipTo optimization for file format prior to 1.4rc2 in order to avoid a bug in
79 // skipTo implementation of these versions
80 skipInterval
= System
.Int32
.MaxValue
;
84 indexInterval
= input
.ReadInt();
85 skipInterval
= input
.ReadInt();
90 public System
.Object
Clone()
92 SegmentTermEnum clone
= null;
95 clone
= (SegmentTermEnum
) base.MemberwiseClone();
97 catch (System
.Exception
)
101 clone
.input
= (IndexInput
) input
.Clone();
102 clone
.termInfo
= new TermInfo(termInfo
);
104 clone
.termBuffer
= (TermBuffer
) termBuffer
.Clone();
105 clone
.prevBuffer
= (TermBuffer
) prevBuffer
.Clone();
106 clone
.scratch
= null;
111 internal void Seek(long pointer
, int p
, Term t
, TermInfo ti
)
120 /// <summary>Increments the enumeration to the next element. True if one exists.</summary>
121 public override bool Next()
123 if (position
++ >= size
- 1)
129 prevBuffer
.Set(termBuffer
);
130 termBuffer
.Read(input
, fieldInfos
);
132 termInfo
.docFreq
= input
.ReadVInt(); // read doc freq
133 termInfo
.freqPointer
+= input
.ReadVLong(); // read freq pointer
134 termInfo
.proxPointer
+= input
.ReadVLong(); // read prox pointer
138 // just read skipOffset in order to increment file pointer;
139 // value is never used since skipTo is switched off
142 if (termInfo
.docFreq
> formatM1SkipInterval
)
144 termInfo
.skipOffset
= input
.ReadVInt();
150 if (termInfo
.docFreq
>= skipInterval
)
151 termInfo
.skipOffset
= input
.ReadVInt();
155 indexPointer
+= input
.ReadVLong(); // read index pointer
160 /// <summary>Optimized scan, without allocating new terms. </summary>
161 internal void ScanTo(Term term
)
164 scratch
= new TermBuffer();
166 while (scratch
.CompareTo(termBuffer
) > 0 && Next())
171 /// <summary>Returns the current Term in the enumeration.
172 /// Initially invalid, valid after next() called for the first time.
174 public override Term
Term()
176 return termBuffer
.ToTerm();
179 /// <summary>Returns the previous Term enumerated. Initially null.</summary>
182 return prevBuffer
.ToTerm();
185 /// <summary>Returns the current TermInfo in the enumeration.
186 /// Initially invalid, valid after next() called for the first time.
188 internal TermInfo
TermInfo()
190 return new TermInfo(termInfo
);
193 /// <summary>Sets the argument to the current TermInfo in the enumeration.
194 /// Initially invalid, valid after next() called for the first time.
196 internal void TermInfo(TermInfo ti
)
201 /// <summary>Returns the docFreq from the current TermInfo in the enumeration.
202 /// Initially invalid, valid after next() called for the first time.
204 public override int DocFreq()
206 return termInfo
.docFreq
;
209 /* Returns the freqPointer from the current TermInfo in the enumeration.
210 Initially invalid, valid after next() called for the first time.*/
211 internal long FreqPointer()
213 return termInfo
.freqPointer
;
216 /* Returns the proxPointer from the current TermInfo in the enumeration.
217 Initially invalid, valid after next() called for the first time.*/
218 internal long ProxPointer()
220 return termInfo
.proxPointer
;
223 /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
224 public override void Close()