19 using Lucene.Net.Support;
23 namespace Lucene.Net.Index
26 internal class SegmentTermDocs :
TermDocs
28 protected internal SegmentReader parent;
30 protected internal int count;
31 protected internal int df;
36 private readonly
int skipInterval;
37 private readonly
int maxSkipLevels;
38 private DefaultSkipListReader skipListReader;
40 private long freqBasePointer;
41 private long proxBasePointer;
43 private long skipPointer;
44 private bool haveSkipped;
46 protected internal bool currentFieldStoresPayloads;
47 protected internal bool currentFieldOmitTermFreqAndPositions;
49 private bool isDisposed;
51 public SegmentTermDocs(SegmentReader parent)
54 this.freqStream = (
IndexInput) parent.core.freqStream.Clone();
57 this.deletedDocs = parent.deletedDocs;
59 this.skipInterval = parent.core.GetTermsReader().SkipInterval;
60 this.maxSkipLevels = parent.core.GetTermsReader().MaxSkipLevels;
63 public virtual void Seek(
Term term)
65 TermInfo ti = parent.core.GetTermsReader().Get(term);
69 public virtual void Seek(
TermEnum termEnum)
75 if (termEnum is SegmentTermEnum && ((SegmentTermEnum) termEnum).fieldInfos == parent.core.fieldInfos)
78 var segmentTermEnum = ((SegmentTermEnum) termEnum);
79 term = segmentTermEnum.Term;
80 ti = segmentTermEnum.TermInfo();
86 ti = parent.core.GetTermsReader().Get(term);
95 FieldInfo fi = parent.core.fieldInfos.FieldInfo(term.Field);
96 currentFieldOmitTermFreqAndPositions = (fi != null) && fi.omitTermFreqAndPositions;
97 currentFieldStoresPayloads = (fi != null) && fi.storePayloads;
106 freqBasePointer = ti.freqPointer;
107 proxBasePointer = ti.proxPointer;
108 skipPointer = freqBasePointer + ti.skipOffset;
109 freqStream.Seek(freqBasePointer);
114 public void Dispose()
119 [Obsolete(
"Use Dispose() instead")]
125 protected virtual void Dispose(
bool disposing)
127 if (isDisposed)
return;
129 freqStream.Dispose();
130 if (skipListReader != null)
131 skipListReader.Dispose();
146 protected internal virtual void SkippingDoc()
150 public virtual bool Next()
156 int docCode = freqStream.ReadVInt();
158 if (currentFieldOmitTermFreqAndPositions)
166 if ((docCode & 1) != 0)
171 freq = freqStream.ReadVInt();
176 if (deletedDocs == null || !deletedDocs.Get(doc))
184 public virtual int Read(
int[] docs,
int[] freqs)
186 int length = docs.Length;
187 if (currentFieldOmitTermFreqAndPositions)
189 return ReadNoTf(docs, freqs, length);
194 while (i < length && count < df)
197 int docCode = freqStream.ReadVInt();
199 if ((docCode & 1) != 0)
204 freq = freqStream.ReadVInt();
207 if (deletedDocs == null || !deletedDocs.Get(doc))
218 private int ReadNoTf(
int[] docs,
int[] freqs,
int length)
221 while (i < length && count < df)
224 doc += freqStream.ReadVInt();
227 if (deletedDocs == null || !deletedDocs.Get(doc))
241 protected internal virtual void SkipProx(
long proxPointer,
int payloadLength)
246 public virtual bool SkipTo(
int target)
248 if (df >= skipInterval)
251 if (skipListReader == null)
252 skipListReader =
new DefaultSkipListReader((
IndexInput) freqStream.Clone(), maxSkipLevels, skipInterval);
257 skipListReader.Init(skipPointer, freqBasePointer, proxBasePointer, df, currentFieldStoresPayloads);
261 int newCount = skipListReader.SkipTo(target);
262 if (newCount > count)
264 freqStream.Seek(skipListReader.GetFreqPointer());
265 SkipProx(skipListReader.GetProxPointer(), skipListReader.GetPayloadLength());
267 doc = skipListReader.GetDoc();
278 while (target > doc);