20 using Lucene.Net.Documents;
27 namespace Lucene.Net.Index
32 internal const byte FIELD_IS_TOKENIZED = (0x1);
33 internal const byte FIELD_IS_BINARY = (0x2);
34 [Obsolete(
"Kept for backwards-compatibility with <3.0 indexes; will be removed in 4.0")]
35 internal const byte FIELD_IS_COMPRESSED = (0x4);
38 internal const int FORMAT = 0;
41 internal const int FORMAT_VERSION_UTF8_LENGTH_IN_BYTES = 1;
44 internal static int FORMAT_LUCENE_3_0_NO_COMPRESSED_FIELDS = 2;
49 internal static readonly
int FORMAT_CURRENT = FORMAT_LUCENE_3_0_NO_COMPRESSED_FIELDS;
57 private readonly
bool doClose;
67 fieldsStream = d.CreateOutput(fieldsName);
68 fieldsStream.WriteInt(FORMAT_CURRENT);
79 catch (System.Exception)
85 d.DeleteFile(fieldsName);
87 catch (System.Exception)
98 indexStream = d.CreateOutput(indexName);
99 indexStream.WriteInt(FORMAT_CURRENT);
110 catch (System.IO.IOException)
115 d.DeleteFile(fieldsName);
117 catch (System.Exception)
123 d.DeleteFile(indexName);
125 catch (System.Exception)
145 this.fieldsStream = stream;
152 internal void FlushDocument(
int numStoredFields,
RAMOutputStream buffer)
154 indexStream.WriteLong(fieldsStream.FilePointer);
155 fieldsStream.WriteVInt(numStoredFields);
156 buffer.WriteTo(fieldsStream);
159 internal void SkipDocument()
161 indexStream.WriteLong(fieldsStream.FilePointer);
162 fieldsStream.WriteVInt(0);
165 internal void Flush()
168 fieldsStream.Flush();
171 public void Dispose()
178 if (fieldsStream != null)
182 fieldsStream.Close();
190 catch (System.IO.IOException)
194 if (indexStream != null)
206 catch (System.IO.IOException)
214 if (indexStream != null)
231 fieldsStream.WriteVInt(fi.number);
238 fieldsStream.WriteByte(bits);
247 fieldsStream.WriteVInt(len);
248 fieldsStream.WriteBytes(data, offset, len);
262 internal void AddRawDocuments(
IndexInput stream,
int[] lengths,
int numDocs)
264 long position = fieldsStream.FilePointer;
265 long start = position;
266 for (
int i = 0; i < numDocs; i++)
268 indexStream.WriteLong(position);
269 position += lengths[i];
271 fieldsStream.CopyBytes(stream, position - start);
272 System.Diagnostics.Debug.Assert(fieldsStream.FilePointer == position);
275 internal void AddDocument(
Document doc)
277 indexStream.WriteLong(fieldsStream.FilePointer);
280 int storedCount = fields.Count(field => field.
IsStored);
281 fieldsStream.WriteVInt(storedCount);
286 WriteField(fieldInfos.FieldInfo(field.
Name), field);