19 using Lucene.Net.Support;
22 namespace Lucene.Net.Index
24 internal sealed
class SegmentTermPositions : SegmentTermDocs,
TermPositions
27 private int proxCount;
31 private int payloadLength;
34 private bool needToLoadPayload;
38 private long lazySkipPointer = - 1;
39 private int lazySkipProxCount = 0;
41 internal SegmentTermPositions(SegmentReader p):base(p)
43 this.proxStream = null;
50 lazySkipPointer = ti.proxPointer;
52 lazySkipProxCount = 0;
55 needToLoadPayload =
false;
58 protected override void Dispose(
bool disposing)
60 base.Dispose(disposing);
61 if (proxStream != null)
65 public int NextPosition()
67 if (currentFieldOmitTermFreqAndPositions)
73 return position += ReadDeltaPosition();
76 private int ReadDeltaPosition()
78 int delta = proxStream.ReadVInt();
79 if (currentFieldStoresPayloads)
87 payloadLength = proxStream.ReadVInt();
90 needToLoadPayload =
true;
95 protected internal override void SkippingDoc()
98 lazySkipProxCount += freq;
101 public override bool Next()
105 lazySkipProxCount += proxCount;
117 public override int Read(
int[] docs,
int[] freqs)
119 throw new System.NotSupportedException(
"TermPositions does not support processing multiple documents in one call. Use TermDocs instead.");
124 protected internal override void SkipProx(
long proxPointer,
int payloadLength)
127 lazySkipPointer = proxPointer;
128 lazySkipProxCount = 0;
130 this.payloadLength = payloadLength;
131 needToLoadPayload =
false;
134 private void SkipPositions(
int n)
136 System.Diagnostics.Debug.Assert(!currentFieldOmitTermFreqAndPositions);
137 for (
int f = n; f > 0; f--)
145 private void SkipPayload()
147 if (needToLoadPayload && payloadLength > 0)
149 proxStream.Seek(proxStream.FilePointer + payloadLength);
151 needToLoadPayload =
false;
164 private void LazySkip()
166 if (proxStream == null)
169 proxStream = (
IndexInput) parent.core.proxStream.Clone();
176 if (lazySkipPointer != - 1)
178 proxStream.Seek(lazySkipPointer);
179 lazySkipPointer = - 1;
182 if (lazySkipProxCount != 0)
184 SkipPositions(lazySkipProxCount);
185 lazySkipProxCount = 0;
189 public int PayloadLength
191 get {
return payloadLength; }
194 public byte[] GetPayload(byte[] data,
int offset)
196 if (!needToLoadPayload)
198 throw new System.IO.IOException(
"Either no payload exists at this term position or an attempt was made to load it more than once.");
204 if (data == null || data.Length - offset < payloadLength)
208 retArray =
new byte[payloadLength];
216 proxStream.ReadBytes(retArray, retOffset, payloadLength);
217 needToLoadPayload =
false;
221 public bool IsPayloadAvailable
223 get {
return needToLoadPayload && payloadLength > 0; }