public override FieldsProducer FieldsProducer(SegmentReadState state) { string fileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, EXTENSION); ChecksumIndexInput @in = state.Directory.OpenChecksumInput(fileName, IOContext.READONCE); var fields = new SortedDictionary <string, TermsReader>(); try { CodecUtil.CheckHeader(@in, CODEC_NAME, VERSION_START, VERSION_CURRENT); while (true) { int termCount = @in.ReadVInt(); if (termCount == 0) { break; } TermsReader termsReader = new TermsReader(state.FieldInfos, @in, termCount); // System.out.println("load field=" + termsReader.field.name); fields.Add(termsReader.field.Name, termsReader); } CodecUtil.CheckFooter(@in); } finally { @in.Dispose(); } return(new FieldsProducerAnonymousInnerClassHelper(this, fields)); }
public override FieldInfos Read(Directory directory, string segmentName, string segmentSuffix, IOContext context) { string fileName = IndexFileNames.SegmentFileName(segmentName, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION); ChecksumIndexInput input = directory.OpenChecksumInput(fileName, context); bool success = false; try { int codecVersion = CodecUtil.CheckHeader(input, Lucene46FieldInfosFormat.CODEC_NAME, Lucene46FieldInfosFormat.FORMAT_START, Lucene46FieldInfosFormat.FORMAT_CURRENT); int size = input.ReadVInt(); //read in the size FieldInfo[] infos = new FieldInfo[size]; for (int i = 0; i < size; i++) { string name = input.ReadString(); int fieldNumber = input.ReadVInt(); byte bits = input.ReadByte(); bool isIndexed = (bits & Lucene46FieldInfosFormat.IS_INDEXED) != 0; bool storeTermVector = (bits & Lucene46FieldInfosFormat.STORE_TERMVECTOR) != 0; bool omitNorms = (bits & Lucene46FieldInfosFormat.OMIT_NORMS) != 0; bool storePayloads = (bits & Lucene46FieldInfosFormat.STORE_PAYLOADS) != 0; FieldInfo.IndexOptions indexOptions; if (!isIndexed) { indexOptions = default(FieldInfo.IndexOptions); } else if ((bits & Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) { indexOptions = FieldInfo.IndexOptions.DOCS_ONLY; } else if ((bits & Lucene46FieldInfosFormat.OMIT_POSITIONS) != 0) { indexOptions = FieldInfo.IndexOptions.DOCS_AND_FREQS; } else if ((bits & Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) { indexOptions = FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS; } else { indexOptions = FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; } // DV Types are packed in one byte byte val = input.ReadByte(); FieldInfo.DocValuesType_e?docValuesType = GetDocValuesType(input, (sbyte)(val & 0x0F)); FieldInfo.DocValuesType_e?normsType = GetDocValuesType(input, (sbyte)(((int)((uint)val >> 4)) & 0x0F)); long dvGen = input.ReadLong(); IDictionary <string, string> attributes = input.ReadStringStringMap(); infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, omitNorms, storePayloads, indexOptions, docValuesType, normsType, CollectionsHelper.UnmodifiableMap(attributes)); infos[i].DocValuesGen = dvGen; } if (codecVersion >= Lucene46FieldInfosFormat.FORMAT_CHECKSUM) { CodecUtil.CheckFooter(input); } else { CodecUtil.CheckEOF(input); } FieldInfos fieldInfos = new FieldInfos(infos); success = true; return(fieldInfos); } finally { if (success) { input.Dispose(); } else { IOUtils.CloseWhileHandlingException(input); } } }
/// <summary> /// Go to the chunk containing the provided doc ID. /// </summary> internal void Next(int doc) { Debug.Assert(doc >= DocBase + ChunkDocs, doc + " " + DocBase + " " + ChunkDocs); FieldsStream.Seek(OuterInstance.IndexReader.GetStartPointer(doc)); int docBase = FieldsStream.ReadVInt(); int chunkDocs = FieldsStream.ReadVInt(); if (docBase < this.DocBase + this.ChunkDocs || docBase + chunkDocs > OuterInstance.NumDocs) { throw new CorruptIndexException("Corrupted: current docBase=" + this.DocBase + ", current numDocs=" + this.ChunkDocs + ", new docBase=" + docBase + ", new numDocs=" + chunkDocs + " (resource=" + FieldsStream + ")"); } this.DocBase = docBase; this.ChunkDocs = chunkDocs; if (chunkDocs > NumStoredFields.Length) { int newLength = ArrayUtil.Oversize(chunkDocs, 4); NumStoredFields = new int[newLength]; Lengths = new int[newLength]; } if (chunkDocs == 1) { NumStoredFields[0] = FieldsStream.ReadVInt(); Lengths[0] = FieldsStream.ReadVInt(); } else { int bitsPerStoredFields = FieldsStream.ReadVInt(); if (bitsPerStoredFields == 0) { CollectionsHelper.Fill(NumStoredFields, 0, chunkDocs, FieldsStream.ReadVInt()); } else if (bitsPerStoredFields > 31) { throw new CorruptIndexException("bitsPerStoredFields=" + bitsPerStoredFields + " (resource=" + FieldsStream + ")"); } else { PackedInts.ReaderIterator it = PackedInts.GetReaderIteratorNoHeader(FieldsStream, PackedInts.Format.PACKED, OuterInstance.PackedIntsVersion, chunkDocs, bitsPerStoredFields, 1); for (int i = 0; i < chunkDocs; ++i) { NumStoredFields[i] = (int)it.Next(); } } int bitsPerLength = FieldsStream.ReadVInt(); if (bitsPerLength == 0) { CollectionsHelper.Fill(Lengths, 0, chunkDocs, FieldsStream.ReadVInt()); } else if (bitsPerLength > 31) { throw new CorruptIndexException("bitsPerLength=" + bitsPerLength); } else { PackedInts.ReaderIterator it = PackedInts.GetReaderIteratorNoHeader(FieldsStream, PackedInts.Format.PACKED, OuterInstance.PackedIntsVersion, chunkDocs, bitsPerLength, 1); for (int i = 0; i < chunkDocs; ++i) { Lengths[i] = (int)it.Next(); } } } }