public override void VisitDocument(int n, StoredFieldVisitor visitor)
 {
     if (Debugging.AssertsEnabled)
     {
         Debugging.Assert(n >= 0 && n < maxDoc);
     }
     @in.VisitDocument(n, visitor);
 }
        private void ReadField(StoredFieldVisitor visitor, FieldInfo info, int bits)
        {
            int numeric = bits & Lucene40StoredFieldsWriter.FIELD_IS_NUMERIC_MASK;

            if (numeric != 0)
            {
                switch (numeric)
                {
                case Lucene40StoredFieldsWriter.FIELD_IS_NUMERIC_INT:
                    visitor.Int32Field(info, fieldsStream.ReadInt32());
                    return;

                case Lucene40StoredFieldsWriter.FIELD_IS_NUMERIC_LONG:
                    visitor.Int64Field(info, fieldsStream.ReadInt64());
                    return;

                case Lucene40StoredFieldsWriter.FIELD_IS_NUMERIC_FLOAT:
                    visitor.SingleField(info, J2N.BitConversion.Int32BitsToSingle(fieldsStream.ReadInt32()));
                    return;

                case Lucene40StoredFieldsWriter.FIELD_IS_NUMERIC_DOUBLE:
                    visitor.DoubleField(info, J2N.BitConversion.Int64BitsToDouble(fieldsStream.ReadInt64()));
                    return;

                default:
                    throw new CorruptIndexException("Invalid numeric type: " + numeric.ToString("x"));
                }
            }
            else
            {
                int length = fieldsStream.ReadVInt32();
                var bytes  = new byte[length];
                fieldsStream.ReadBytes(bytes, 0, length);
                if ((bits & Lucene40StoredFieldsWriter.FIELD_IS_BINARY) != 0)
                {
                    visitor.BinaryField(info, bytes);
                }
                else
                {
#pragma warning disable 612, 618
                    visitor.StringField(info, IOUtils.CHARSET_UTF_8.GetString(bytes));
#pragma warning restore 612, 618
                }
            }
        }
Beispiel #3
0
 private void ReadField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor)
 {
     ReadLine();
     if (Debugging.AssertsEnabled)
     {
         Debugging.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.VALUE));
     }
     if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_STRING))
     {
         visitor.StringField(fieldInfo,
                             Encoding.UTF8.GetString(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
                                                     _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_BINARY))
     {
         var copy = new byte[_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length];
         Array.Copy(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, copy, 0, copy.Length);
         visitor.BinaryField(fieldInfo, copy);
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_INT))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.Int32Field(fieldInfo, J2N.Numerics.Int32.Parse(_scratchUtf16.ToString(), NumberFormatInfo.InvariantInfo));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_LONG))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.Int64Field(fieldInfo, J2N.Numerics.Int64.Parse(_scratchUtf16.ToString(), NumberFormatInfo.InvariantInfo));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_FLOAT))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.SingleField(fieldInfo, J2N.Numerics.Single.Parse(_scratchUtf16.ToString(), NumberStyle.Float, NumberFormatInfo.InvariantInfo));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_DOUBLE))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.DoubleField(fieldInfo, J2N.Numerics.Double.Parse(_scratchUtf16.ToString(), NumberStyle.Float, NumberFormatInfo.InvariantInfo));
     }
 }
        private void ReadField(StoredFieldVisitor visitor, FieldInfo info, int bits)
        {
            int numeric = bits & FIELD_IS_NUMERIC_MASK;

            if (numeric != 0)
            {
                switch (numeric)
                {
                case FIELD_IS_NUMERIC_INT:
                    visitor.IntField(info, FieldsStream.ReadInt());
                    return;

                case FIELD_IS_NUMERIC_LONG:
                    visitor.LongField(info, FieldsStream.ReadLong());
                    return;

                case FIELD_IS_NUMERIC_FLOAT:
                    visitor.FloatField(info, Number.IntBitsToFloat(FieldsStream.ReadInt()));
                    return;

                case FIELD_IS_NUMERIC_DOUBLE:
                    visitor.DoubleField(info, BitConverter.Int64BitsToDouble(FieldsStream.ReadLong()));
                    return;

                default:
                    throw new CorruptIndexException("Invalid numeric type: " + numeric.ToString("x"));
                }
            }
            else
            {
                int length = FieldsStream.ReadVInt();
                var bytes  = new byte[length];
                FieldsStream.ReadBytes(bytes, 0, length);
                if ((bits & FIELD_IS_BINARY) != 0)
                {
                    visitor.BinaryField(info, bytes);
                }
                else
                {
                    visitor.StringField(info, IOUtils.CHARSET_UTF_8.GetString(bytes));
                }
            }
        }
Beispiel #5
0
 private void ReadField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor)
 {
     ReadLine();
     Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.VALUE));
     if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_STRING))
     {
         visitor.StringField(fieldInfo,
                             Encoding.UTF8.GetString(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
                                                     _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_BINARY))
     {
         var copy = new byte[_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length];
         Array.Copy(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, copy, 0, copy.Length);
         visitor.BinaryField(fieldInfo, copy);
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_INT))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.Int32Field(fieldInfo, Convert.ToInt32(_scratchUtf16.ToString(), CultureInfo.InvariantCulture));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_LONG))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.Int64Field(fieldInfo, Convert.ToInt64(_scratchUtf16.ToString(), CultureInfo.InvariantCulture));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_FLOAT))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.SingleField(fieldInfo, Convert.ToSingle(_scratchUtf16.ToString(), CultureInfo.InvariantCulture));
     }
     else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_DOUBLE))
     {
         UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length, _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
                                 _scratchUtf16);
         visitor.DoubleField(fieldInfo, Convert.ToDouble(_scratchUtf16.ToString(), CultureInfo.InvariantCulture));
     }
 }
Beispiel #6
0
        private static void ReadField(DataInput @in, StoredFieldVisitor visitor, FieldInfo info, int bits)
        {
            switch (bits & CompressingStoredFieldsWriter.TYPE_MASK)
            {
            case CompressingStoredFieldsWriter.BYTE_ARR:
                int length = @in.ReadVInt32();
                var data   = new byte[length];
                @in.ReadBytes(data, 0, length);
                visitor.BinaryField(info, data);
                break;

            case CompressingStoredFieldsWriter.STRING:
                length = @in.ReadVInt32();
                data   = new byte[length];
                @in.ReadBytes(data, 0, length);
#pragma warning disable 612, 618
                visitor.StringField(info, IOUtils.CHARSET_UTF_8.GetString(data));
#pragma warning restore 612, 618
                break;

            case CompressingStoredFieldsWriter.NUMERIC_INT32:
                visitor.Int32Field(info, @in.ReadInt32());
                break;

            case CompressingStoredFieldsWriter.NUMERIC_SINGLE:
                visitor.SingleField(info, J2N.BitConversion.Int32BitsToSingle(@in.ReadInt32()));
                break;

            case CompressingStoredFieldsWriter.NUMERIC_INT64:
                visitor.Int64Field(info, @in.ReadInt64());
                break;

            case CompressingStoredFieldsWriter.NUMERIC_DOUBLE:
                visitor.DoubleField(info, J2N.BitConversion.Int64BitsToDouble(@in.ReadInt64()));
                break;

            default:
                throw AssertionError.Create("Unknown type flag: " + bits.ToString("x"));
            }
        }
        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"));
            }
        }
Beispiel #8
0
        public override void VisitDocument(int n, StoredFieldVisitor visitor)
        {
            _input.Seek(_offsets[n]);
            ReadLine();
            Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.NUM));
            var numFields = ParseInt32At(SimpleTextStoredFieldsWriter.NUM.Length);

            for (var i = 0; i < numFields; i++)
            {
                ReadLine();
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.FIELD));
                int       fieldNumber = ParseInt32At(SimpleTextStoredFieldsWriter.FIELD.Length);
                FieldInfo fieldInfo   = _fieldInfos.FieldInfo(fieldNumber);
                ReadLine();
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.NAME));
                ReadLine();
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.TYPE));

                BytesRef type;
                if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_STRING, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
                {
                    type = SimpleTextStoredFieldsWriter.TYPE_STRING;
                }
                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_BINARY, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
                {
                    type = SimpleTextStoredFieldsWriter.TYPE_BINARY;
                }
                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_INT, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
                {
                    type = SimpleTextStoredFieldsWriter.TYPE_INT;
                }
                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_LONG, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
                {
                    type = SimpleTextStoredFieldsWriter.TYPE_LONG;
                }
                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_FLOAT, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
                {
                    type = SimpleTextStoredFieldsWriter.TYPE_FLOAT;
                }
                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_DOUBLE, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
                {
                    type = SimpleTextStoredFieldsWriter.TYPE_DOUBLE;
                }
                else
                {
                    throw new Exception("unknown field type");
                }

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

                case StoredFieldVisitor.Status.NO:
                    ReadLine();
                    Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.VALUE));
                    break;

                case StoredFieldVisitor.Status.STOP:
                    return;
                }
            }
        }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: @Override public void document(final int docID, final org.apache.lucene.index.StoredFieldVisitor visitor) throws java.io.IOException
 //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
 public override void document(int docID, StoredFieldVisitor visitor)
 {
     @in.document(docMap.newToOld(docID), visitor);
 }
Beispiel #10
0
 public override void VisitDocument(int n, StoredFieldVisitor visitor)
 {
     Debug.Assert(n >= 0 && n < maxDoc);
     @in.VisitDocument(n, visitor);
 }
        private void ReadField(StoredFieldVisitor visitor, FieldInfo info, int bits)
        {
            int numeric = bits & FIELD_IS_NUMERIC_MASK;
            if (numeric != 0)
            {
                switch (numeric)
                {
                    case FIELD_IS_NUMERIC_INT:
                        visitor.IntField(info, FieldsStream.ReadInt());
                        return;

                    case FIELD_IS_NUMERIC_LONG:
                        visitor.LongField(info, FieldsStream.ReadLong());
                        return;

                    case FIELD_IS_NUMERIC_FLOAT:
                        visitor.FloatField(info, Number.IntBitsToFloat(FieldsStream.ReadInt()));
                        return;

                    case FIELD_IS_NUMERIC_DOUBLE:
                        visitor.DoubleField(info, BitConverter.Int64BitsToDouble(FieldsStream.ReadLong()));
                        return;

                    default:
                        throw new CorruptIndexException("Invalid numeric type: " + numeric.ToString("x"));
                }
            }
            else
            {
                int length = FieldsStream.ReadVInt();
                var bytes = new byte[length];
                FieldsStream.ReadBytes(bytes, 0, length);
                if ((bits & FIELD_IS_BINARY) != 0)
                {
                    visitor.BinaryField(info, bytes);
                }
                else
                {
                    visitor.StringField(info, IOUtils.CHARSET_UTF_8.GetString(bytes));
                }
            }
        }
        public override void VisitDocument(int n, StoredFieldVisitor visitor)
        {
            SeekIndex(n);
            FieldsStream.Seek(IndexStream.ReadLong());

            int numFields = FieldsStream.ReadVInt();
            for (int fieldIDX = 0; fieldIDX < numFields; fieldIDX++)
            {
                int fieldNumber = FieldsStream.ReadVInt();
                FieldInfo fieldInfo = FieldInfos.FieldInfo(fieldNumber);

                int bits = FieldsStream.ReadByte() & 0xFF;
                Debug.Assert(bits <= (FIELD_IS_NUMERIC_MASK | FIELD_IS_BINARY), "bits=" + bits.ToString("x"));

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

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

                    case StoredFieldVisitor.Status.STOP:
                        return;
                }
            }
        }
Beispiel #13
0
 /// <summary>
 /// Visit the stored fields for document <code>n</code> </summary>
 public abstract void VisitDocument(int n, StoredFieldVisitor visitor);
Beispiel #14
0
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
 }
Beispiel #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void document(final int docID, final org.apache.lucene.index.StoredFieldVisitor visitor) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        public override void document(int docID, StoredFieldVisitor visitor)
        {
            @in.document(docMap.newToOld(docID), 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;
                }
            }
        }
Beispiel #17
0
 /// <summary>
 /// Sugar for <code>.IndexReader.Document(docID, fieldVisitor)</code> </summary>
 /// <seealso cref="IndexReader.Document(int, StoredFieldVisitor)"/>
 public virtual void Doc(int docID, StoredFieldVisitor fieldVisitor)
 {
     reader.Document(docID, fieldVisitor);
 }
Beispiel #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void document(int docID, org.apache.lucene.index.StoredFieldVisitor visitor) throws java.io.IOException
        public override void Document(int docID, StoredFieldVisitor visitor)
        {
            visitor.stringField(_dummyFieldInfo, docID.ToString().GetBytes(Encoding.UTF8));
        }
Beispiel #19
0
        public override void VisitDocument(int docID, StoredFieldVisitor visitor)
        {
            fieldsStream.Seek(indexReader.GetStartPointer(docID));

            int docBase   = fieldsStream.ReadVInt32();
            int chunkDocs = fieldsStream.ReadVInt32();

            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.ReadVInt32();
                offset          = 0;
                length          = fieldsStream.ReadVInt32();
                totalLength     = length;
            }
            else
            {
                int bitsPerStoredFields = fieldsStream.ReadVInt32();
                if (bitsPerStoredFields == 0)
                {
                    numStoredFields = fieldsStream.ReadVInt32();
                }
                else if (bitsPerStoredFields > 31)
                {
                    throw new CorruptIndexException("bitsPerStoredFields=" + bitsPerStoredFields + " (resource=" + fieldsStream + ")");
                }
                else
                {
                    long filePointer           = fieldsStream.Position; // LUCENENET specific: Renamed from getFilePointer() to match FileStream
                    PackedInt32s.Reader reader = PackedInt32s.GetDirectReaderNoHeader(fieldsStream, PackedInt32s.Format.PACKED, packedIntsVersion, chunkDocs, bitsPerStoredFields);
                    numStoredFields = (int)(reader.Get(docID - docBase));
                    fieldsStream.Seek(filePointer + PackedInt32s.Format.PACKED.ByteCount(packedIntsVersion, chunkDocs, bitsPerStoredFields));
                }

                int bitsPerLength = fieldsStream.ReadVInt32();
                if (bitsPerLength == 0)
                {
                    length      = fieldsStream.ReadVInt32();
                    offset      = (docID - docBase) * length;
                    totalLength = chunkDocs * length;
                }
                else if (bitsPerStoredFields > 31)
                {
                    throw new CorruptIndexException("bitsPerLength=" + bitsPerLength + " (resource=" + fieldsStream + ")");
                }
                else
                {
                    PackedInt32s.IReaderIterator it = PackedInt32s.GetReaderIteratorNoHeader(fieldsStream, PackedInt32s.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 >= CompressingStoredFieldsWriter.VERSION_BIG_CHUNKS && totalLength >= 2 * chunkSize)
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(chunkSize > 0);
                    Debugging.Assert(offset < chunkSize);
                }

                decompressor.Decompress(fieldsStream, chunkSize, offset, Math.Min(length, chunkSize - offset), bytes);
                documentInput = new DataInputAnonymousClass(this, length);
            }
            else
            {
                BytesRef bytes = totalLength <= BUFFER_REUSE_THRESHOLD ? this.bytes : new BytesRef();
                decompressor.Decompress(fieldsStream, totalLength, offset, length, bytes);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(bytes.Length == length);
                }
                documentInput = new ByteArrayDataInput(bytes.Bytes, bytes.Offset, bytes.Length);
            }

            for (int fieldIDX = 0; fieldIDX < numStoredFields; fieldIDX++)
            {
                long      infoAndBits = documentInput.ReadVInt64();
                int       fieldNumber = (int)infoAndBits.TripleShift(CompressingStoredFieldsWriter.TYPE_BITS);
                FieldInfo fieldInfo   = fieldInfos.FieldInfo(fieldNumber);

                int bits = (int)(infoAndBits & CompressingStoredFieldsWriter.TYPE_MASK);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(bits <= CompressingStoredFieldsWriter.NUMERIC_DOUBLE, "bits={0:x}", bits);
                }

                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;
                }
            }
        }
Beispiel #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void visitDocument(int n, index.StoredFieldVisitor visitor) throws java.io.IOException
        public override void visitDocument(int n, StoredFieldVisitor visitor)
        {
            @in.seek(offsets[n]);
            readLine();
            Debug.Assert(StringHelper.StartsWith(scratch, NUM));
            int numFields = parseIntAt(NUM.length);

            for (int i = 0; i < numFields; i++)
            {
                readLine();
                Debug.Assert(StringHelper.StartsWith(scratch, FIELD));
                int       fieldNumber = parseIntAt(FIELD.length);
                FieldInfo fieldInfo   = fieldInfos.fieldInfo(fieldNumber);
                readLine();
                Debug.Assert(StringHelper.StartsWith(scratch, NAME));
                readLine();
                Debug.Assert(StringHelper.StartsWith(scratch, TYPE));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final util.BytesRef type;
                BytesRef type;
                if (equalsAt(TYPE_STRING, scratch, TYPE.length))
                {
                    type = TYPE_STRING;
                }
                else if (equalsAt(TYPE_BINARY, scratch, TYPE.length))
                {
                    type = TYPE_BINARY;
                }
                else if (equalsAt(TYPE_INT, scratch, TYPE.length))
                {
                    type = TYPE_INT;
                }
                else if (equalsAt(TYPE_LONG, scratch, TYPE.length))
                {
                    type = TYPE_LONG;
                }
                else if (equalsAt(TYPE_FLOAT, scratch, TYPE.length))
                {
                    type = TYPE_FLOAT;
                }
                else if (equalsAt(TYPE_DOUBLE, scratch, TYPE.length))
                {
                    type = TYPE_DOUBLE;
                }
                else
                {
                    throw new Exception("unknown field type");
                }

                switch (visitor.needsField(fieldInfo))
                {
                case YES:
                    readField(type, fieldInfo, visitor);
                    break;

                case NO:
                    readLine();
                    Debug.Assert(StringHelper.StartsWith(scratch, VALUE));
                    break;

                case STOP:
                    return;
                }
            }
        }
Beispiel #21
0
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     m_input.Document(docMap.NewToOld(docID), visitor);
 }
Beispiel #22
0
 // for highlighter
 public override void Document(int docID, StoredFieldVisitor visitor)
 {
     visitor.StringField(
         new FieldInfo("1", false, 1, false, true, false, IndexOptions.NONE, DocValuesType.NONE,
                       DocValuesType.NONE, new Dictionary <string, string>()), "test1");
 }