public FSTTermsWriter(SegmentWriteState state, PostingsWriterBase postingsWriter) { var termsFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, TERMS_EXTENSION); _postingsWriter = postingsWriter; _fieldInfos = state.FieldInfos; _output = state.Directory.CreateOutput(termsFileName, state.Context); var success = false; try { WriteHeader(_output); _postingsWriter.Init(_output); success = true; } finally { if (!success) { IOUtils.CloseWhileHandlingException(_output); } } }
public override void Files(SegmentCommitInfo info, ICollection <string> files) { if (info.HasDeletions()) { files.Add(IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.DelGen)); } }
public SimpleTextStoredFieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) { _fieldInfos = fn; var success = false; try { _input = directory.OpenInput( IndexFileNames.SegmentFileName(si.Name, "", SimpleTextStoredFieldsWriter.FIELDS_EXTENSION), context); success = true; } finally { if (!success) { try { Dispose(); } catch { // ensure we throw our original exception } } } ReadIndex(si.DocCount); }
internal DirectDocValuesConsumer(SegmentWriteState state, string dataCodec, string dataExtension, string metaCodec, string metaExtension) { maxDoc = state.SegmentInfo.DocCount; bool success = false; try { string dataName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, dataExtension); data = state.Directory.CreateOutput(dataName, state.Context); CodecUtil.WriteHeader(data, dataCodec, DirectDocValuesProducer.VERSION_CURRENT); string metaName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, metaExtension); meta = state.Directory.CreateOutput(metaName, state.Context); CodecUtil.WriteHeader(meta, metaCodec, DirectDocValuesProducer.VERSION_CURRENT); success = true; } finally { if (!success) { IOUtils.CloseWhileHandlingException(this); } } }
public override sealed void Abort() { try { Dispose(); } finally { IOUtils.DeleteFilesIgnoringExceptions(_directory, IndexFileNames.SegmentFileName(_segment, "", VECTORS_EXTENSION)); } }
public FSTTermsReader(SegmentReadState state, PostingsReaderBase postingsReader) { string termsFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, FSTTermsWriter.TERMS_EXTENSION); this.postingsReader = postingsReader; IndexInput @in = state.Directory.OpenInput(termsFileName, state.Context); bool success = false; try { version = ReadHeader(@in); if (version >= FSTTermsWriter.TERMS_VERSION_CHECKSUM) { CodecUtil.ChecksumEntireFile(@in); } this.postingsReader.Init(@in); SeekDir(@in); FieldInfos fieldInfos = state.FieldInfos; int numFields = @in.ReadVInt(); for (int i = 0; i < numFields; i++) { int fieldNumber = @in.ReadVInt(); FieldInfo fieldInfo = fieldInfos.FieldInfo(fieldNumber); long numTerms = @in.ReadVLong(); long sumTotalTermFreq = fieldInfo.FieldIndexOptions == IndexOptions.DOCS_ONLY ? -1 : @in.ReadVLong(); long sumDocFreq = @in.ReadVLong(); int docCount = @in.ReadVInt(); int longsSize = @in.ReadVInt(); TermsReader current = new TermsReader(this, fieldInfo, @in, numTerms, sumTotalTermFreq, sumDocFreq, docCount, longsSize); TermsReader previous = fields[fieldInfo.Name] = current; CheckFieldSummary(state.SegmentInfo, @in, current, previous); } success = true; } finally { if (success) { IOUtils.Close(@in); } else { IOUtils.CloseWhileHandlingException(@in); } } }
public override Bits ReadLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) { Debug.Assert(info.HasDeletions()); var scratch = new BytesRef(); var scratchUtf16 = new CharsRef(); var fileName = IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.DelGen); ChecksumIndexInput input = null; var success = false; try { input = dir.OpenChecksumInput(fileName, context); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SIZE)); var size = ParseIntAt(scratch, SIZE.Length, scratchUtf16); var bits = new BitArray(size); SimpleTextUtil.ReadLine(input, scratch); while (!scratch.Equals(END)) { Debug.Assert(StringHelper.StartsWith(scratch, DOC)); var docid = ParseIntAt(scratch, DOC.Length, scratchUtf16); bits.Set(docid, true); SimpleTextUtil.ReadLine(input, scratch); } SimpleTextUtil.CheckFooter(input); success = true; return(new SimpleTextBits(bits, size)); } finally { if (success) { IOUtils.Close(input); } else { IOUtils.CloseWhileHandlingException(input); } } }
public SimpleTextStoredFieldsWriter(Directory directory, string segment, IOContext context) { _directory = directory; _segment = segment; var success = false; try { _output = directory.CreateOutput(IndexFileNames.SegmentFileName(segment, "", FIELDS_EXTENSION), context); success = true; } finally { if (!success) { Abort(); } } }
public SimpleTextTermVectorsWriter(Directory directory, string segment, IOContext context) { _directory = directory; _segment = segment; bool success = false; try { _output = directory.CreateOutput(IndexFileNames.SegmentFileName(segment, "", VECTORS_EXTENSION), context); success = true; } finally { if (!success) { Abort(); } } }
public override void WriteLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) { var set = ((SimpleTextBits)bits).BITS; var size = bits.Length(); var scratch = new BytesRef(); var fileName = IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.NextDelGen); IndexOutput output = null; var success = false; try { output = dir.CreateOutput(fileName, context); SimpleTextUtil.Write(output, SIZE); SimpleTextUtil.Write(output, Convert.ToString(size), scratch); SimpleTextUtil.WriteNewline(output); for (int i = set.NextSetBit(0); i >= 0; i = set.NextSetBit(i + 1)) { SimpleTextUtil.Write(output, DOC); SimpleTextUtil.Write(output, Convert.ToString(i), scratch); SimpleTextUtil.WriteNewline(output); } SimpleTextUtil.Write(output, END); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.WriteChecksum(output, scratch); success = true; } finally { if (success) { IOUtils.Close(output); } else { IOUtils.CloseWhileHandlingException(output); } } }
public SimpleTextTermVectorsReader(Directory directory, SegmentInfo si, IOContext context) { bool success = false; try { _input = directory.OpenInput(IndexFileNames.SegmentFileName(si.Name, "", VECTORS_EXTENSION), context); success = true; } finally { if (!success) { try { Dispose(); } // ensure we throw our original exception catch (Exception) { } } } ReadIndex(si.DocCount); }
public override void Write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos, IOContext context) { var fileName = IndexFileNames.SegmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION); var output = directory.CreateOutput(fileName, context); var scratch = new BytesRef(); var success = false; try { SimpleTextUtil.Write(output, NUMFIELDS); SimpleTextUtil.Write(output, Convert.ToString(infos.Size()), scratch); SimpleTextUtil.WriteNewline(output); foreach (FieldInfo fi in infos) { SimpleTextUtil.Write(output, NAME); SimpleTextUtil.Write(output, fi.Name, scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, NUMBER); SimpleTextUtil.Write(output, Convert.ToString(fi.Number), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, ISINDEXED); SimpleTextUtil.Write(output, Convert.ToString(fi.Indexed), scratch); SimpleTextUtil.WriteNewline(output); if (fi.Indexed) { Debug.Assert(fi.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !fi.HasPayloads()); SimpleTextUtil.Write(output, INDEXOPTIONS); SimpleTextUtil.Write(output, fi.FieldIndexOptions.ToString(), scratch); SimpleTextUtil.WriteNewline(output); } SimpleTextUtil.Write(output, STORETV); SimpleTextUtil.Write(output, Convert.ToString(fi.HasVectors()), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, PAYLOADS); SimpleTextUtil.Write(output, Convert.ToString(fi.HasPayloads()), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, NORMS); SimpleTextUtil.Write(output, Convert.ToString(!fi.OmitsNorms()), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, NORMS_TYPE); SimpleTextUtil.Write(output, GetDocValuesType(fi.NormType), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, DOCVALUES); SimpleTextUtil.Write(output, GetDocValuesType(fi.DocValuesType), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, DOCVALUES_GEN); SimpleTextUtil.Write(output, Convert.ToString(fi.DocValuesGen), scratch); SimpleTextUtil.WriteNewline(output); IDictionary <string, string> atts = fi.Attributes(); int numAtts = atts == null ? 0 : atts.Count; SimpleTextUtil.Write(output, NUM_ATTS); SimpleTextUtil.Write(output, Convert.ToString(numAtts), scratch); SimpleTextUtil.WriteNewline(output); if (numAtts <= 0 || atts == null) { continue; } foreach (var entry in atts) { SimpleTextUtil.Write(output, ATT_KEY); SimpleTextUtil.Write(output, entry.Key, scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, ATT_VALUE); SimpleTextUtil.Write(output, entry.Value, scratch); SimpleTextUtil.WriteNewline(output); } } SimpleTextUtil.WriteChecksum(output, scratch); success = true; } finally { if (success) { output.Dispose(); } else { IOUtils.CloseWhileHandlingException(output); } } }
public override SegmentInfo Read(Directory directory, string segmentName, IOContext context) { BytesRef scratch = new BytesRef(); string segFileName = IndexFileNames.SegmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION); ChecksumIndexInput input = directory.OpenChecksumInput(segFileName, context); bool success = false; try { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_VERSION)); string version = ReadString(SI_VERSION.length, scratch); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_DOCCOUNT)); int docCount = Convert.ToInt32(ReadString(SI_DOCCOUNT.length, scratch)); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_USECOMPOUND)); bool isCompoundFile = Convert.ToBoolean(ReadString(SI_USECOMPOUND.length, scratch)); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_NUM_DIAG)); int numDiag = Convert.ToInt32(ReadString(SI_NUM_DIAG.length, scratch)); IDictionary <string, string> diagnostics = new Dictionary <string, string>(); for (int i = 0; i < numDiag; i++) { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_DIAG_KEY)); string key = ReadString(SI_DIAG_KEY.length, scratch); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_DIAG_VALUE)); string value = ReadString(SI_DIAG_VALUE.length, scratch); diagnostics[key] = value; } SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_NUM_FILES)); int numFiles = Convert.ToInt32(ReadString(SI_NUM_FILES.length, scratch)); HashSet <string> files = new HashSet <string>(); for (int i = 0; i < numFiles; i++) { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SI_FILE)); string fileName = ReadString(SI_FILE.length, scratch); files.Add(fileName); } SimpleTextUtil.CheckFooter(input); SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount, isCompoundFile, null, diagnostics); info.Files = files; success = true; return(info); } finally { if (!success) { IOUtils.CloseWhileHandlingException(input); } else { input.Close(); } } }
/// <summary> /// Creates a postings writer with the specified PackedInts overhead ratio </summary> // TODO: does this ctor even make sense? public Lucene41PostingsWriter(SegmentWriteState state, float acceptableOverheadRatio) : base() { DocOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.DOC_EXTENSION), state.Context); IndexOutput posOut = null; IndexOutput payOut = null; bool success = false; try { CodecUtil.WriteHeader(DocOut, DOC_CODEC, VERSION_CURRENT); ForUtil = new ForUtil(acceptableOverheadRatio, DocOut); if (state.FieldInfos.HasProx()) { PosDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE]; posOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.POS_EXTENSION), state.Context); CodecUtil.WriteHeader(posOut, POS_CODEC, VERSION_CURRENT); if (state.FieldInfos.HasPayloads()) { PayloadBytes = new sbyte[128]; PayloadLengthBuffer = new int[ForUtil.MAX_DATA_SIZE]; } else { PayloadBytes = null; PayloadLengthBuffer = null; } if (state.FieldInfos.HasOffsets()) { OffsetStartDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE]; OffsetLengthBuffer = new int[ForUtil.MAX_DATA_SIZE]; } else { OffsetStartDeltaBuffer = null; OffsetLengthBuffer = null; } if (state.FieldInfos.HasPayloads() || state.FieldInfos.HasOffsets()) { payOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.PAY_EXTENSION), state.Context); CodecUtil.WriteHeader(payOut, PAY_CODEC, VERSION_CURRENT); } } else { PosDeltaBuffer = null; PayloadLengthBuffer = null; OffsetStartDeltaBuffer = null; OffsetLengthBuffer = null; PayloadBytes = null; } this.PayOut = payOut; this.PosOut = posOut; success = true; } finally { if (!success) { IOUtils.CloseWhileHandlingException(DocOut, posOut, payOut); } } DocDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE]; FreqBuffer = new int[ForUtil.MAX_DATA_SIZE]; // TODO: should we try skipping every 2/4 blocks...? SkipWriter = new Lucene41SkipWriter(MaxSkipLevels, Lucene41PostingsFormat.BLOCK_SIZE, state.SegmentInfo.DocCount, DocOut, posOut, payOut); Encoded = new byte[ForUtil.MAX_ENCODED_SIZE]; }
public override void Write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) { var segFileName = IndexFileNames.SegmentFileName(si.Name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION); si.AddFile(segFileName); var success = false; var output = dir.CreateOutput(segFileName, ioContext); try { var scratch = new BytesRef(); SimpleTextUtil.Write(output, SI_VERSION); SimpleTextUtil.Write(output, si.Version, scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, SI_DOCCOUNT); SimpleTextUtil.Write(output, Convert.ToString(si.DocCount, CultureInfo.InvariantCulture), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, SI_USECOMPOUND); SimpleTextUtil.Write(output, Convert.ToString(si.UseCompoundFile, CultureInfo.InvariantCulture).ToLowerInvariant(), scratch); SimpleTextUtil.WriteNewline(output); IDictionary <string, string> diagnostics = si.Diagnostics; int numDiagnostics = diagnostics == null ? 0 : diagnostics.Count; SimpleTextUtil.Write(output, SI_NUM_DIAG); SimpleTextUtil.Write(output, Convert.ToString(numDiagnostics, CultureInfo.InvariantCulture), scratch); SimpleTextUtil.WriteNewline(output); if (numDiagnostics > 0) { foreach (var diagEntry in diagnostics) { SimpleTextUtil.Write(output, SI_DIAG_KEY); SimpleTextUtil.Write(output, diagEntry.Key, scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, SI_DIAG_VALUE); SimpleTextUtil.Write(output, diagEntry.Value, scratch); SimpleTextUtil.WriteNewline(output); } } var files = si.Files; var numFiles = files == null ? 0 : files.Count; SimpleTextUtil.Write(output, SI_NUM_FILES); SimpleTextUtil.Write(output, Convert.ToString(numFiles, CultureInfo.InvariantCulture), scratch); SimpleTextUtil.WriteNewline(output); if (numFiles > 0) { foreach (var fileName in files) { SimpleTextUtil.Write(output, SI_FILE); SimpleTextUtil.Write(output, fileName, scratch); SimpleTextUtil.WriteNewline(output); } } SimpleTextUtil.WriteChecksum(output, scratch); success = true; } finally { if (!success) { IOUtils.CloseWhileHandlingException(output); try { dir.DeleteFile(segFileName); } catch (Exception) { //Esnure we throw original exeception } } else { output.Dispose(); } } }
private readonly HashSet <string> _fieldsSeen = new HashSet <string>(); // for asserting public SimpleTextDocValuesWriter(SegmentWriteState state, string ext) { data = state.Directory.CreateOutput( IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, ext), state.Context); numDocs = state.SegmentInfo.DocCount; }
public SimpleTextDocValuesReader(SegmentReadState state, string ext) { DATA = state.Directory.OpenInput( IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, ext), state.Context); MAX_DOC = state.SegmentInfo.DocCount; while (true) { ReadLine(); if (SCRATCH.Equals(SimpleTextDocValuesWriter.END)) { break; } Debug.Assert(StartsWith(SimpleTextDocValuesWriter.FIELD), SCRATCH.Utf8ToString()); var fieldName = StripPrefix(SimpleTextDocValuesWriter.FIELD); var field = new OneField(); FIELDS[fieldName] = field; ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.TYPE), SCRATCH.Utf8ToString()); var dvType = (FieldInfo.DocValuesType_e) Enum.Parse(typeof(FieldInfo.DocValuesType_e), StripPrefix(SimpleTextDocValuesWriter.TYPE)); if (dvType == FieldInfo.DocValuesType_e.NUMERIC) { ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.MINVALUE), "got " + SCRATCH.Utf8ToString() + " field=" + fieldName + " ext=" + ext); field.MinValue = Convert.ToInt64(StripPrefix(SimpleTextDocValuesWriter.MINVALUE)); ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.PATTERN)); field.Pattern = StripPrefix(SimpleTextDocValuesWriter.PATTERN); field.DataStartFilePointer = DATA.FilePointer; DATA.Seek(DATA.FilePointer + (1 + field.Pattern.Length + 2) * MAX_DOC); } else if (dvType == FieldInfo.DocValuesType_e.BINARY) { ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.MAXLENGTH)); field.MaxLength = Convert.ToInt32(StripPrefix(SimpleTextDocValuesWriter.MAXLENGTH)); ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.PATTERN)); field.Pattern = StripPrefix(SimpleTextDocValuesWriter.PATTERN); field.DataStartFilePointer = DATA.FilePointer; DATA.Seek(DATA.FilePointer + (9 + field.Pattern.Length + field.MaxLength + 2) * MAX_DOC); } else if (dvType == FieldInfo.DocValuesType_e.SORTED || dvType == FieldInfo.DocValuesType_e.SORTED_SET) { ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.NUMVALUES)); field.NumValues = Convert.ToInt64(StripPrefix(SimpleTextDocValuesWriter.NUMVALUES)); ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.MAXLENGTH)); field.MaxLength = Convert.ToInt32(StripPrefix(SimpleTextDocValuesWriter.MAXLENGTH)); ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.PATTERN)); field.Pattern = StripPrefix(SimpleTextDocValuesWriter.PATTERN); ReadLine(); Debug.Assert(StartsWith(SimpleTextDocValuesWriter.ORDPATTERN)); field.OrdPattern = StripPrefix(SimpleTextDocValuesWriter.ORDPATTERN); field.DataStartFilePointer = DATA.FilePointer; DATA.Seek(DATA.FilePointer + (9 + field.Pattern.Length + field.MaxLength) * field.NumValues + (1 + field.OrdPattern.Length) * MAX_DOC); } else { throw new InvalidEnumArgumentException(); } } // We should only be called from above if at least one // field has DVs: Debug.Assert(FIELDS.Count > 0); }
internal static string GetPostingsFileName(string segment, string segmentSuffix) { return(IndexFileNames.SegmentFileName(segment, segmentSuffix, POSTINGS_EXTENSION)); }