19 using System.Collections.Generic;
24 namespace Lucene.Net.Index
28 private void InitBlock()
30 docFreeList =
new PerDoc[1];
35 internal PerDoc[] docFreeList;
36 internal int freeCount;
40 internal int lastDocID;
45 this.docWriter = docWriter;
53 internal override void CreatePostings(
RawPostingList[] postings,
int start,
int count)
55 int end = start + count;
56 for (
int i = start; i < end; i++)
57 postings[i] =
new PostingList();
74 if (state.numDocsInStore > 0)
77 Fill(state.numDocsInStore - docWriter.DocStoreOffset);
84 foreach(var entry
in threadsAndFields)
86 foreach(var field
in entry.Value)
89 perField.termsHashPerField.
Reset();
90 perField.ShrinkHash();
94 perThread.termsHashPerThread.Reset(
true);
107 Fill(state.numDocsInStore - docWriter.DocStoreOffset);
112 System.Diagnostics.Debug.Assert(state.docStoreSegmentName != null);
114 if (4 + ((
long) state.numDocsInStore) * 16 != state.directory.FileLength(fileName))
115 throw new System.SystemException(
"after flush: tvx size mismatch: " + state.numDocsInStore +
" docs vs " + state.directory.FileLength(fileName) +
" length in bytes of " + fileName +
" file exists?=" + state.directory.FileExists(fileName));
130 internal int allocCount;
132 internal PerDoc GetPerDoc()
139 if (allocCount > docFreeList.Length)
144 System.Diagnostics.Debug.Assert(allocCount == 1 + docFreeList.Length);
145 docFreeList =
new PerDoc[
ArrayUtil.GetNextSize(allocCount)];
147 return new PerDoc(
this);
150 return docFreeList[--freeCount];
157 internal void Fill(
int docID)
159 int docStoreOffset = docWriter.DocStoreOffset;
160 int end = docID + docStoreOffset;
163 long tvfPosition = tvf.FilePointer;
164 while (lastDocID < end)
166 tvx.WriteLong(tvd.FilePointer);
168 tvx.WriteLong(tvfPosition);
174 internal void InitTermVectorsWriter()
181 System.String docStoreSegment = docWriter.DocStoreSegment;
183 if (docStoreSegment == null)
186 System.Diagnostics.Debug.Assert(docStoreSegment != null);
192 tvx = docWriter.directory.CreateOutput(docStoreSegment +
"." + IndexFileNames.VECTORS_INDEX_EXTENSION);
193 tvd = docWriter.directory.CreateOutput(docStoreSegment +
"." + IndexFileNames.VECTORS_DOCUMENTS_EXTENSION);
194 tvf = docWriter.directory.CreateOutput(docStoreSegment +
"." + IndexFileNames.VECTORS_FIELDS_EXTENSION);
196 tvx.WriteInt(TermVectorsReader.FORMAT_CURRENT);
197 tvd.WriteInt(TermVectorsReader.FORMAT_CURRENT);
198 tvf.WriteInt(TermVectorsReader.FORMAT_CURRENT);
200 docWriter.AddOpenFile(docStoreSegment +
"." + IndexFileNames.VECTORS_INDEX_EXTENSION);
201 docWriter.AddOpenFile(docStoreSegment +
"." + IndexFileNames.VECTORS_FIELDS_EXTENSION);
202 docWriter.AddOpenFile(docStoreSegment +
"." + IndexFileNames.VECTORS_DOCUMENTS_EXTENSION);
209 internal void FinishDocument(PerDoc perDoc)
214 System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint(
"TermVectorsTermsWriter.finishDocument start"));
216 InitTermVectorsWriter();
221 tvx.WriteLong(tvd.FilePointer);
222 tvx.WriteLong(tvf.FilePointer);
223 tvd.WriteVInt(perDoc.numVectorFields);
224 if (perDoc.numVectorFields > 0)
226 for (
int i = 0; i < perDoc.numVectorFields; i++)
227 tvd.WriteVInt(perDoc.fieldNumbers[i]);
228 System.Diagnostics.Debug.Assert(0 == perDoc.fieldPointers [0]);
229 long lastPos = perDoc.fieldPointers[0];
230 for (
int i = 1; i < perDoc.numVectorFields; i++)
232 long pos = perDoc.fieldPointers[i];
233 tvd.WriteVLong(pos - lastPos);
236 perDoc.perDocTvf.WriteTo(tvf);
237 perDoc.numVectorFields = 0;
240 System.Diagnostics.Debug.Assert(lastDocID == perDoc.docID + docWriter.DocStoreOffset);
245 System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint(
"TermVectorsTermsWriter.finishDocument end"));
249 public bool FreeRAM()
256 public override void Abort()
264 catch (System.Exception)
275 catch (System.Exception)
286 catch (System.Exception)
294 internal void Free(PerDoc doc)
298 System.Diagnostics.Debug.Assert(freeCount < docFreeList.Length);
299 docFreeList[freeCount++] = doc;
303 internal class PerDoc:DocumentsWriter.DocWriter
305 public PerDoc(TermVectorsTermsWriter enclosingInstance)
307 InitBlock(enclosingInstance);
309 private void InitBlock(TermVectorsTermsWriter enclosingInstance)
311 this.enclosingInstance = enclosingInstance;
312 buffer = enclosingInstance.docWriter.NewPerDocBuffer();
315 private TermVectorsTermsWriter enclosingInstance;
316 public TermVectorsTermsWriter Enclosing_Instance
320 return enclosingInstance;
325 internal DocumentsWriter.PerDocBuffer buffer;
327 internal int numVectorFields;
329 internal int[] fieldNumbers =
new int[1];
330 internal long[] fieldPointers =
new long[1];
332 internal void Reset()
339 public override void Abort()
342 Enclosing_Instance.Free(
this);
345 internal void AddField(
int fieldNumber)
347 if (numVectorFields == fieldNumbers.Length)
349 fieldNumbers =
ArrayUtil.Grow(fieldNumbers);
350 fieldPointers =
ArrayUtil.Grow(fieldPointers);
352 fieldNumbers[numVectorFields] = fieldNumber;
353 fieldPointers[numVectorFields] = perDocTvf.FilePointer;
357 public override long SizeInBytes()
359 return buffer.SizeInBytes;
362 public override void Finish()
364 Enclosing_Instance.FinishDocument(
this);
368 internal sealed
class PostingList:RawPostingList
371 internal int lastOffset;
372 internal int lastPosition;
375 internal override int BytesPerPosting()
377 return RawPostingList.BYTES_SIZE + 3 * DocumentsWriter.INT_NUM_BYTE;