19 using System.Collections.Generic;
22 namespace Lucene.Net.Index
31 internal override void CreatePostings(
RawPostingList[] postings,
int start,
int count)
33 int end = start + count;
34 for (
int i = start; i < end; i++)
35 postings[i] =
new PostingList();
38 private static int compareText(
char[] text1,
int pos1,
char[] text2,
int pos2)
42 char c1 = text1[pos1++];
43 char c2 = text2[pos2++];
48 else if (0xffff == c1)
53 else if (0xffff == c1)
58 internal override void CloseDocStore(SegmentWriteState state)
61 public override void Abort()
75 var allFields =
new List<FreqProxTermsWriterPerField>();
77 foreach(var entry
in threadsAndFields)
79 var fields = entry.Value;
81 foreach(var i
in fields)
84 if (perField.termsHashPerField.numPostings > 0)
85 allFields.Add(perField);
91 int numAllFields = allFields.Count;
108 while (start < numAllFields)
110 FieldInfo fieldInfo = allFields[start].fieldInfo;
111 System.String fieldName = fieldInfo.name;
114 while (end < numAllFields && allFields[end].fieldInfo.name.Equals(fieldName))
118 for (
int i = start; i < end; i++)
120 fields[i - start] = allFields[i];
124 fieldInfo.storePayloads |= fields[i - start].hasPayloads;
129 AppendPostings(fields, consumer);
131 for (
int i = 0; i < fields.Length; i++)
134 int numPostings = perField.numPostings;
136 perField.ShrinkHash(numPostings);
143 foreach(var entry
in threadsAndFields)
146 perThread.termsHashPerThread.Reset(
true);
152 private byte[] payloadBuffer;
160 int numFields = fields.Length;
164 for (
int i = 0; i < numFields; i++)
168 System.Diagnostics.Debug.Assert(fms.field.fieldInfo == fields [0].fieldInfo);
171 bool result = fms.NextTerm();
172 System.Diagnostics.Debug.Assert(result);
175 FormatPostingsTermsConsumer termsConsumer = consumer.AddField(fields[0].fieldInfo);
177 FreqProxFieldMergeState[] termStates =
new FreqProxFieldMergeState[numFields];
179 bool currentFieldOmitTermFreqAndPositions = fields[0].fieldInfo.omitTermFreqAndPositions;
181 while (numFields > 0)
185 termStates[0] = mergeStates[0];
188 for (
int i = 1; i < numFields; i++)
190 char[] text = mergeStates[i].text;
191 int textOffset = mergeStates[i].textOffset;
192 int cmp = compareText(text, textOffset, termStates[0].text, termStates[0].textOffset);
196 termStates[0] = mergeStates[i];
200 termStates[numToMerge++] = mergeStates[i];
203 FormatPostingsDocsConsumer docConsumer = termsConsumer.AddTerm(termStates[0].text, termStates[0].textOffset);
208 while (numToMerge > 0)
211 FreqProxFieldMergeState minState = termStates[0];
212 for (
int i = 1; i < numToMerge; i++)
213 if (termStates[i].docID < minState.docID)
214 minState = termStates[i];
216 int termDocFreq = minState.termFreq;
218 FormatPostingsPositionsConsumer posConsumer = docConsumer.AddDoc(minState.docID, termDocFreq);
220 ByteSliceReader prox = minState.prox;
225 if (!currentFieldOmitTermFreqAndPositions)
230 for (
int j = 0; j < termDocFreq; j++)
232 int code = prox.ReadVInt();
233 position += (code >> 1);
239 payloadLength = prox.ReadVInt();
241 if (payloadBuffer == null || payloadBuffer.Length < payloadLength)
242 payloadBuffer =
new byte[payloadLength];
244 prox.ReadBytes(payloadBuffer, 0, payloadLength);
249 posConsumer.AddPosition(position, payloadBuffer, 0, payloadLength);
252 posConsumer.Finish();
255 if (!minState.NextDoc())
260 for (
int i = 0; i < numToMerge; i++)
261 if (termStates[i] != minState)
262 termStates[upto++] = termStates[i];
264 System.Diagnostics.Debug.Assert(upto == numToMerge);
268 if (!minState.NextTerm())
273 for (
int i = 0; i < numFields; i++)
274 if (mergeStates[i] != minState)
275 mergeStates[upto++] = mergeStates[i];
277 System.Diagnostics.Debug.Assert(upto == numFields);
282 docConsumer.Finish();
285 termsConsumer.Finish();
290 internal sealed
class PostingList:RawPostingList
292 internal int docFreq;
293 internal int lastDocID;
294 internal int lastDocCode;
295 internal int lastPosition;
298 internal override int BytesPerPosting()
300 return RawPostingList.BYTES_SIZE + 4 * DocumentsWriter.INT_NUM_BYTE;