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
;
19 using BitVector
= Lucene
.Net
.Util
.BitVector
;
21 namespace Lucene
.Net
.Index
24 public class SegmentTermDocs
: TermDocs
26 protected internal SegmentReader parent
;
27 protected internal IndexInput freqStream
;
28 protected internal int count
;
29 protected internal int df
;
30 protected internal BitVector deletedDocs
;
34 private int skipInterval
;
36 private int skipCount
;
37 private IndexInput skipStream
;
39 private long freqPointer
;
40 private long proxPointer
;
41 private long skipPointer
;
42 private bool haveSkipped
;
44 public SegmentTermDocs(SegmentReader parent
)
47 this.freqStream
= (IndexInput
) parent
.freqStream
.Clone();
48 this.deletedDocs
= parent
.deletedDocs
;
49 this.skipInterval
= parent
.tis
.GetSkipInterval();
52 public virtual void Seek(Term term
)
54 TermInfo ti
= parent
.tis
.Get(term
);
58 public virtual void Seek(TermEnum termEnum
)
62 // use comparison of fieldinfos to verify that termEnum belongs to the same segment as this SegmentTermDocs
63 if (termEnum
is SegmentTermEnum
&& ((SegmentTermEnum
) termEnum
).fieldInfos
== parent
.fieldInfos
)
65 ti
= ((SegmentTermEnum
) termEnum
).TermInfo();
68 ti
= parent
.tis
.Get(termEnum
.Term());
73 internal virtual void Seek(TermInfo ti
)
86 numSkips
= df
/ skipInterval
;
87 freqPointer
= ti
.freqPointer
;
88 proxPointer
= ti
.proxPointer
;
89 skipPointer
= freqPointer
+ ti
.skipOffset
;
90 freqStream
.Seek(freqPointer
);
95 public virtual void Close()
98 if (skipStream
!= null)
111 protected internal virtual void SkippingDoc()
115 public virtual bool Next()
122 int docCode
= freqStream
.ReadVInt();
123 doc
+= (int) (((uint) docCode
) >> 1); // shift off low bit
124 if ((docCode
& 1) != 0)
129 freq
= freqStream
.ReadVInt(); // else read freq
133 if (deletedDocs
== null || !deletedDocs
.Get(doc
))
140 /// <summary>Optimized implementation. </summary>
141 public virtual int Read(int[] docs
, int[] freqs
)
143 int length
= docs
.Length
;
145 while (i
< length
&& count
< df
)
148 // manually inlined call to next() for speed
149 int docCode
= freqStream
.ReadVInt();
150 doc
+= (int) (((uint) docCode
) >> 1); // shift off low bit
151 if ((docCode
& 1) != 0)
156 freq
= freqStream
.ReadVInt(); // else read freq
159 if (deletedDocs
== null || !deletedDocs
.Get(doc
))
169 /// <summary>Overridden by SegmentTermPositions to skip in prox stream. </summary>
170 protected internal virtual void SkipProx(long proxPointer
)
174 /// <summary>Optimized implementation. </summary>
175 public virtual bool SkipTo(int target
)
177 if (df
>= skipInterval
)
181 if (skipStream
== null)
182 skipStream
= (IndexInput
) freqStream
.Clone(); // lazily clone
186 // lazily seek skip stream
187 skipStream
.Seek(skipPointer
);
192 int lastSkipDoc
= skipDoc
;
193 long lastFreqPointer
= freqStream
.GetFilePointer();
194 long lastProxPointer
= - 1;
195 int numSkipped
= - 1 - (count
% skipInterval
);
197 while (target
> skipDoc
)
199 lastSkipDoc
= skipDoc
;
200 lastFreqPointer
= freqPointer
;
201 lastProxPointer
= proxPointer
;
203 if (skipDoc
!= 0 && skipDoc
>= doc
)
204 numSkipped
+= skipInterval
;
206 if (skipCount
>= numSkips
)
209 skipDoc
+= skipStream
.ReadVInt();
210 freqPointer
+= skipStream
.ReadVInt();
211 proxPointer
+= skipStream
.ReadVInt();
216 // if we found something to skip, then skip it
217 if (lastFreqPointer
> freqStream
.GetFilePointer())
219 freqStream
.Seek(lastFreqPointer
);
220 SkipProx(lastProxPointer
);
227 // done skipping, now just scan
233 while (target
> doc
);