protected override void Dispose(bool disposing) { if (disposing) { if (m_output != null) { try { long dirStart = m_output.GetFilePointer(); m_output.WriteVInt32(fields.Count); foreach (FieldMetaData field in fields) { m_output.WriteVInt32(field.FieldInfo.Number); m_output.WriteVInt64(field.NumTerms); m_output.WriteVInt64(field.TermsStartPointer); if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY) { m_output.WriteVInt64(field.SumTotalTermFreq); } m_output.WriteVInt64(field.SumDocFreq); m_output.WriteVInt32(field.DocCount); if (VERSION_CURRENT >= VERSION_META_ARRAY) { m_output.WriteVInt32(field.Int64sSize); } } WriteTrailer(dirStart); CodecUtil.WriteFooter(m_output); } finally { IOUtils.Dispose(m_output, postingsWriter, termsIndexWriter); m_output = null; } } } }
public override void Dispose() { if (_output == null) { return; } try { var dirStart = _output.FilePointer; _output.WriteVInt(_fields.Count); foreach (var field in _fields) { _output.WriteVInt(field.FieldInfo.Number); _output.WriteVLong(field.NumTerms); _output.WriteVLong(field.TermsStartPointer); if (field.FieldInfo.FieldIndexOptions != FieldInfo.IndexOptions.DOCS_ONLY) { _output.WriteVLong(field.SumTotalTermFreq); } _output.WriteVLong(field.SumDocFreq); _output.WriteVInt(field.DocCount); if (VERSION_CURRENT >= VERSION_META_ARRAY) { _output.WriteVInt(field.LongsSize); } } WriteTrailer(dirStart); CodecUtil.WriteFooter(_output); } finally { IOUtils.Close(_output, PostingsWriter, _termsIndexWriter); _output = null; } }
public override void Finish(FieldInfos fis, int numDocs) { if (numBufferedDocs > 0) { Flush(); } else { if (Debugging.AssertsEnabled) { Debugging.Assert(bufferedDocs.Length == 0); } } if (docBase != numDocs) { throw RuntimeException.Create("Wrote " + docBase + " docs, finish called with numDocs=" + numDocs); } indexWriter.Finish(numDocs, fieldsStream.Position); // LUCENENET specific: Renamed from getFilePointer() to match FileStream CodecUtil.WriteFooter(fieldsStream); if (Debugging.AssertsEnabled) { Debugging.Assert(bufferedDocs.Length == 0); } }
protected override void Dispose(bool disposing) { if (disposing) { // TODO: add a finish() at least to PushBase? DV too...? bool success = false; try { if (DocOut != null) { CodecUtil.WriteFooter(DocOut); } if (PosOut != null) { CodecUtil.WriteFooter(PosOut); } if (PayOut != null) { CodecUtil.WriteFooter(PayOut); } success = true; } finally { if (success) { IOUtils.Close(DocOut, PosOut, PayOut); } else { IOUtils.CloseWhileHandlingException(DocOut, PosOut, PayOut); } DocOut = PosOut = PayOut = null; } } }
/// <summary> /// Save a single segment's info. </summary> public override void Write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) { string fileName = IndexFileNames.SegmentFileName(si.Name, "", Lucene46SegmentInfoFormat.SI_EXTENSION); si.AddFile(fileName); IndexOutput output = dir.CreateOutput(fileName, ioContext); bool success = false; try { CodecUtil.WriteHeader(output, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_CURRENT); // Write the Lucene version that created this segment, since 3.1 output.WriteString(si.Version); output.WriteInt32(si.DocCount); output.WriteByte((byte)(sbyte)(si.UseCompoundFile ? SegmentInfo.YES : SegmentInfo.NO)); output.WriteStringStringMap(si.Diagnostics); output.WriteStringSet(si.GetFiles()); CodecUtil.WriteFooter(output); success = true; } finally { if (!success) { IOUtils.DisposeWhileHandlingException(output); si.Dir.DeleteFile(fileName); } else { output.Dispose(); } } }
public override void Dispose() { _delegateFieldsConsumer.Dispose(); // Now we are done accumulating values for these fields var nonSaturatedBlooms = (from entry in _bloomFilters.EntrySet() let bloomFilter = entry.Value where !_bfpf._bloomFilterFactory.IsSaturated(bloomFilter, entry.Key) select entry).ToList(); var bloomFileName = IndexFileNames.SegmentFileName( _state.SegmentInfo.Name, _state.SegmentSuffix, BLOOM_EXTENSION); IndexOutput bloomOutput = null; try { bloomOutput = _state.Directory.CreateOutput(bloomFileName, _state.Context); CodecUtil.WriteHeader(bloomOutput, BLOOM_CODEC_NAME, VERSION_CURRENT); // remember the name of the postings format we will delegate to bloomOutput.WriteString(_bfpf._delegatePostingsFormat.Name); // First field in the output file is the number of fields+blooms saved bloomOutput.WriteInt(nonSaturatedBlooms.Count); foreach (var entry in nonSaturatedBlooms) { var fieldInfo = entry.Key; var bloomFilter = entry.Value; bloomOutput.WriteInt(fieldInfo.Number); SaveAppropriatelySizedBloomFilter(bloomOutput, bloomFilter, fieldInfo); } CodecUtil.WriteFooter(bloomOutput); } finally { IOUtils.Close(bloomOutput); } //We are done with large bitsets so no need to keep them hanging around _bloomFilters.Clear(); }
public override void Finish(FieldInfos fis, int numDocs) { if (numBufferedDocs > 0) { Flush(); } else { if (Debugging.AssertsEnabled) { Debugging.Assert(bufferedDocs.Length == 0); } } if (docBase != numDocs) { throw new Exception("Wrote " + docBase + " docs, finish called with numDocs=" + numDocs); } indexWriter.Finish(numDocs, fieldsStream.GetFilePointer()); CodecUtil.WriteFooter(fieldsStream); if (Debugging.AssertsEnabled) { Debugging.Assert(bufferedDocs.Length == 0); } }
public override void Write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos, IOContext context) { string fileName = IndexFileNames.SegmentFileName(segmentName, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION); IndexOutput output = directory.CreateOutput(fileName, context); bool success = false; try { CodecUtil.WriteHeader(output, Lucene46FieldInfosFormat.CODEC_NAME, Lucene46FieldInfosFormat.FORMAT_CURRENT); output.WriteVInt(infos.Size()); foreach (FieldInfo fi in infos) { FieldInfo.IndexOptions?indexOptions = fi.FieldIndexOptions; sbyte bits = 0x0; if (fi.HasVectors()) { bits |= Lucene46FieldInfosFormat.STORE_TERMVECTOR; } if (fi.OmitsNorms()) { bits |= Lucene46FieldInfosFormat.OMIT_NORMS; } if (fi.HasPayloads()) { bits |= Lucene46FieldInfosFormat.STORE_PAYLOADS; } if (fi.Indexed) { bits |= Lucene46FieldInfosFormat.IS_INDEXED; Debug.Assert(indexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !fi.HasPayloads()); if (indexOptions == FieldInfo.IndexOptions.DOCS_ONLY) { bits |= Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS; } else if (indexOptions == FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) { bits |= Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS; } else if (indexOptions == FieldInfo.IndexOptions.DOCS_AND_FREQS) { bits |= Lucene46FieldInfosFormat.OMIT_POSITIONS; } } output.WriteString(fi.Name); output.WriteVInt(fi.Number); output.WriteByte((byte)bits); // pack the DV types in one byte var dv = DocValuesByte(fi.DocValuesType); var nrm = DocValuesByte(fi.NormType); Debug.Assert((dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0); var val = unchecked ((sbyte)(0xff & ((nrm << 4) | dv))); output.WriteByte((byte)val); output.WriteLong(fi.DocValuesGen); output.WriteStringStringMap(fi.Attributes()); } CodecUtil.WriteFooter(output); success = true; } finally { if (success) { output.Dispose(); } else { IOUtils.CloseWhileHandlingException(output); } } }
public override void Write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos, IOContext context) { string fileName = IndexFileNames.SegmentFileName(segmentName, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION); IndexOutput output = directory.CreateOutput(fileName, context); bool success = false; try { CodecUtil.WriteHeader(output, Lucene46FieldInfosFormat.CODEC_NAME, Lucene46FieldInfosFormat.FORMAT_CURRENT); output.WriteVInt32(infos.Count); foreach (FieldInfo fi in infos) { IndexOptions indexOptions = fi.IndexOptions; sbyte bits = 0x0; if (fi.HasVectors) { bits |= Lucene46FieldInfosFormat.STORE_TERMVECTOR; } if (fi.OmitsNorms) { bits |= Lucene46FieldInfosFormat.OMIT_NORMS; } if (fi.HasPayloads) { bits |= Lucene46FieldInfosFormat.STORE_PAYLOADS; } if (fi.IsIndexed) { bits |= Lucene46FieldInfosFormat.IS_INDEXED; // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() if (Debugging.AssertsEnabled) { Debugging.Assert(IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); } if (indexOptions == IndexOptions.DOCS_ONLY) { bits |= Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS; } else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) { bits |= Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS; } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) { bits |= Lucene46FieldInfosFormat.OMIT_POSITIONS; } } output.WriteString(fi.Name); output.WriteVInt32(fi.Number); output.WriteByte((byte)bits); // pack the DV types in one byte var dv = DocValuesByte(fi.DocValuesType); var nrm = DocValuesByte(fi.NormType); if (Debugging.AssertsEnabled) { Debugging.Assert((dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0); } var val = (byte)(0xff & ((nrm << 4) | (byte)dv)); output.WriteByte(val); output.WriteInt64(fi.DocValuesGen); output.WriteStringStringMap(fi.Attributes); } CodecUtil.WriteFooter(output); success = true; } finally { if (success) { output.Dispose(); } else { IOUtils.DisposeWhileHandlingException(output); } } }