Esempio n. 1
0
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     EnsureOpen();
     foreach (AtomicReader reader in storedFieldsReaders)
     {
         reader.Document(docID, visitor);
     }
 }
Esempio n. 2
0
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     CheckBounds(docID);
     FieldsReader.VisitDocument(docID, visitor);
 }
Esempio n. 3
0
 public StoredFieldVisitorAnonymousInnerClassHelper(FieldFilterAtomicReader outerInstance, StoredFieldVisitor visitor)
 {
     this.OuterInstance = outerInstance;
     this.Visitor       = visitor;
 }
Esempio n. 4
0
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     base.Document(docID, new StoredFieldVisitorAnonymousInnerClassHelper(this, visitor));
 }
Esempio n. 5
0
 /// <summary>
 /// Expert: visits the fields of a stored document, for
 /// custom processing/loading of each field. If you
 /// simply want to load all fields, use
 /// <see cref="Document(int)"/>. If you want to load a subset, use
 /// <see cref="DocumentStoredFieldVisitor"/>.
 /// </summary>
 public abstract void Document(int docID, StoredFieldVisitor visitor);
Esempio n. 6
0
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     EnsureOpen();
     @in.Document(docID, visitor);
 }
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     EnsureOpen();
     @in.Document(docID, visitor);
 }
Esempio n. 8
0
 public StoredFieldVisitorAnonymousClass(FieldFilterAtomicReader outerInstance, StoredFieldVisitor visitor)
 {
     this.outerInstance = outerInstance;
     this.visitor       = visitor;
 }
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     EnsureOpen();
     foreach (AtomicReader reader in StoredFieldsReaders)
     {
         reader.Document(docID, visitor);
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Expert: visits the fields of a stored document, for
 ///  custom processing/loading of each field.  If you
 ///  simply want to load all fields, use {@link
 ///  #document(int)}.  If you want to load a subset, use
 ///  <seealso cref="DocumentStoredFieldVisitor"/>.
 /// </summary>
 public abstract void Document(int docID, StoredFieldVisitor visitor);
        public override void VisitDocument(int docID, StoredFieldVisitor visitor)
        {
            FieldsStream.Seek(IndexReader.GetStartPointer(docID));

            int docBase = FieldsStream.ReadVInt();
            int chunkDocs = FieldsStream.ReadVInt();
            if (docID < docBase || docID >= docBase + chunkDocs || docBase + chunkDocs > NumDocs)
            {
                throw new CorruptIndexException("Corrupted: docID=" + docID + ", docBase=" + docBase + ", chunkDocs=" + chunkDocs + ", numDocs=" + NumDocs + " (resource=" + FieldsStream + ")");
            }

            int numStoredFields, offset, length, totalLength;
            if (chunkDocs == 1)
            {
                numStoredFields = FieldsStream.ReadVInt();
                offset = 0;
                length = FieldsStream.ReadVInt();
                totalLength = length;
            }
            else
            {
                int bitsPerStoredFields = FieldsStream.ReadVInt();
                if (bitsPerStoredFields == 0)
                {
                    numStoredFields = FieldsStream.ReadVInt();
                }
                else if (bitsPerStoredFields > 31)
                {
                    throw new CorruptIndexException("bitsPerStoredFields=" + bitsPerStoredFields + " (resource=" + FieldsStream + ")");
                }
                else
                {
                    long filePointer = FieldsStream.FilePointer;
                    PackedInts.Reader reader = PackedInts.GetDirectReaderNoHeader(FieldsStream, PackedInts.Format.PACKED, PackedIntsVersion, chunkDocs, bitsPerStoredFields);
                    numStoredFields = (int)(reader.Get(docID - docBase));
                    FieldsStream.Seek(filePointer + PackedInts.Format.PACKED.ByteCount(PackedIntsVersion, chunkDocs, bitsPerStoredFields));
                }

                int bitsPerLength = FieldsStream.ReadVInt();
                if (bitsPerLength == 0)
                {
                    length = FieldsStream.ReadVInt();
                    offset = (docID - docBase) * length;
                    totalLength = chunkDocs * length;
                }
                else if (bitsPerStoredFields > 31)
                {
                    throw new CorruptIndexException("bitsPerLength=" + bitsPerLength + " (resource=" + FieldsStream + ")");
                }
                else
                {
                    PackedInts.ReaderIterator it = PackedInts.GetReaderIteratorNoHeader(FieldsStream, PackedInts.Format.PACKED, PackedIntsVersion, chunkDocs, bitsPerLength, 1);
                    int off = 0;
                    for (int i = 0; i < docID - docBase; ++i)
                    {
                        off += (int)it.Next();
                    }
                    offset = off;
                    length = (int)it.Next();
                    off += length;
                    for (int i = docID - docBase + 1; i < chunkDocs; ++i)
                    {
                        off += (int)it.Next();
                    }
                    totalLength = off;
                }
            }

            if ((length == 0) != (numStoredFields == 0))
            {
                throw new CorruptIndexException("length=" + length + ", numStoredFields=" + numStoredFields + " (resource=" + FieldsStream + ")");
            }
            if (numStoredFields == 0)
            {
                // nothing to do
                return;
            }

            DataInput documentInput;
            if (Version_Renamed >= CompressingStoredFieldsWriter.VERSION_BIG_CHUNKS && totalLength >= 2 * ChunkSize_Renamed)
            {
                Debug.Assert(ChunkSize_Renamed > 0);
                Debug.Assert(offset < ChunkSize_Renamed);

                Decompressor.Decompress(FieldsStream, ChunkSize_Renamed, offset, Math.Min(length, ChunkSize_Renamed - offset), Bytes);
                documentInput = new DataInputAnonymousInnerClassHelper(this, offset, length);
            }
            else
            {
                BytesRef bytes = totalLength <= BUFFER_REUSE_THRESHOLD ? this.Bytes : new BytesRef();
                Decompressor.Decompress(FieldsStream, totalLength, offset, length, bytes);
                Debug.Assert(bytes.Length == length);
                documentInput = new ByteArrayDataInput((byte[])(Array)bytes.Bytes, bytes.Offset, bytes.Length);
            }

            for (int fieldIDX = 0; fieldIDX < numStoredFields; fieldIDX++)
            {
                long infoAndBits = documentInput.ReadVLong();
                int fieldNumber = (int)((long)((ulong)infoAndBits >> CompressingStoredFieldsWriter.TYPE_BITS));
                FieldInfo fieldInfo = FieldInfos.FieldInfo(fieldNumber);

                int bits = (int)(infoAndBits & CompressingStoredFieldsWriter.TYPE_MASK);
                Debug.Assert(bits <= CompressingStoredFieldsWriter.NUMERIC_DOUBLE, "bits=" + bits.ToString("x"));

                switch (visitor.NeedsField(fieldInfo))
                {
                    case StoredFieldVisitor.Status.YES:
                        ReadField(documentInput, visitor, fieldInfo, bits);
                        break;

                    case StoredFieldVisitor.Status.NO:
                        SkipField(documentInput, bits);
                        break;

                    case StoredFieldVisitor.Status.STOP:
                        return;
                }
            }
        }
        private static void ReadField(DataInput @in, StoredFieldVisitor visitor, FieldInfo info, int bits)
        {
            switch (bits & CompressingStoredFieldsWriter.TYPE_MASK)
            {
                case CompressingStoredFieldsWriter.BYTE_ARR:
                    int length = @in.ReadVInt();
                    var data = new byte[length];
                    @in.ReadBytes(data, 0, length);
                    visitor.BinaryField(info, data);
                    break;

                case CompressingStoredFieldsWriter.STRING:
                    length = @in.ReadVInt();
                    data = new byte[length];
                    @in.ReadBytes(data, 0, length);
                    visitor.StringField(info, IOUtils.CHARSET_UTF_8.GetString((byte[])(Array)data));
                    break;

                case CompressingStoredFieldsWriter.NUMERIC_INT:
                    visitor.IntField(info, @in.ReadInt());
                    break;

                case CompressingStoredFieldsWriter.NUMERIC_FLOAT:
                    visitor.FloatField(info, Number.IntBitsToFloat(@in.ReadInt()));
                    break;

                case CompressingStoredFieldsWriter.NUMERIC_LONG:
                    visitor.LongField(info, @in.ReadLong());
                    break;

                case CompressingStoredFieldsWriter.NUMERIC_DOUBLE:
                    visitor.DoubleField(info, BitConverter.Int64BitsToDouble(@in.ReadLong()));
                    break;

                default:
                    throw new InvalidOperationException("Unknown type flag: " + bits.ToString("x"));
            }
        }