23 namespace Lucene.Net.Index
29 private void InitBlock()
31 docFreeList =
new PerDoc[1];
37 internal int lastDocID;
39 internal PerDoc[] docFreeList;
40 internal int freeCount;
45 this.docWriter = docWriter;
46 this.fieldInfos = fieldInfos;
59 if (state.numDocsInStore > 0)
68 Fill(state.numDocsInStore - docWriter.DocStoreOffset);
71 if (fieldsWriter != null)
76 private void InitFieldsWriter()
78 if (fieldsWriter == null)
80 System.String docStoreSegment = docWriter.DocStoreSegment;
81 if (docStoreSegment != null)
83 System.Diagnostics.Debug.Assert(docStoreSegment != null);
84 fieldsWriter =
new FieldsWriter(docWriter.directory, docStoreSegment, fieldInfos);
96 int inc = state.numDocsInStore - lastDocID;
100 Fill(state.numDocsInStore - docWriter.DocStoreOffset);
103 if (fieldsWriter != null)
105 fieldsWriter.Dispose();
108 System.Diagnostics.Debug.Assert(state.docStoreSegmentName != null);
117 if (4 + ((
long) state.numDocsInStore) * 8 != state.directory.FileLength(fileName))
118 throw new System.SystemException(
"after flush: fdx size mismatch: " + state.numDocsInStore +
" docs vs " + state.directory.FileLength(fileName) +
" length in bytes of " + fileName +
" file exists?=" + state.directory.FileExists(fileName));
123 internal int allocCount;
125 internal PerDoc GetPerDoc()
132 if (allocCount > docFreeList.Length)
137 System.Diagnostics.Debug.Assert(allocCount == 1 + docFreeList.Length);
138 docFreeList =
new PerDoc[
ArrayUtil.GetNextSize(allocCount)];
140 return new PerDoc(
this);
143 return docFreeList[--freeCount];
147 internal void Abort()
151 if (fieldsWriter != null)
155 fieldsWriter.Dispose();
157 catch (System.Exception)
167 internal void Fill(
int docID)
169 int docStoreOffset = docWriter.DocStoreOffset;
173 int end = docID + docStoreOffset;
174 while (lastDocID < end)
176 fieldsWriter.SkipDocument();
181 internal void FinishDocument(PerDoc perDoc)
185 System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint(
"StoredFieldsWriter.finishDocument start"));
191 fieldsWriter.FlushDocument(perDoc.numStoredFields, perDoc.fdt);
195 System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint(
"StoredFieldsWriter.finishDocument end"));
199 public bool FreeRAM()
204 internal void Free(PerDoc perDoc)
208 System.Diagnostics.Debug.Assert(freeCount < docFreeList.Length);
209 System.Diagnostics.Debug.Assert(0 == perDoc.numStoredFields);
210 System.Diagnostics.Debug.Assert(0 == perDoc.fdt.Length);
211 System.Diagnostics.Debug.Assert(0 == perDoc.fdt.FilePointer);
212 docFreeList[freeCount++] = perDoc;
216 internal class PerDoc:DocumentsWriter.DocWriter
218 public PerDoc(StoredFieldsWriter enclosingInstance)
220 InitBlock(enclosingInstance);
222 private void InitBlock(StoredFieldsWriter enclosingInstance)
224 this.enclosingInstance = enclosingInstance;
225 buffer = enclosingInstance.docWriter.NewPerDocBuffer();
228 private StoredFieldsWriter enclosingInstance;
229 public StoredFieldsWriter Enclosing_Instance
233 return enclosingInstance;
238 internal DocumentsWriter.PerDocBuffer buffer ;
240 internal int numStoredFields;
242 internal void Reset()
249 public override void Abort()
252 Enclosing_Instance.Free(
this);
255 public override long SizeInBytes()
257 return buffer.SizeInBytes;
260 public override void Finish()
262 Enclosing_Instance.FinishDocument(
this);