public override int getOrd(int docID)
 {
     if (docID < 0 || docID >= outerInstance.maxDoc)
     {
         throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
     }
     try
     {
         @in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.Length + field.maxLength) + docID * (1 + field.ordPattern.Length));
         SimpleTextUtil.ReadLine(@in, scratch);
         try
         {
             return((long)(int)ordDecoder.parse(scratch.utf8ToString()) - 1);
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse ord (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
Example #2
0
 private void SeekDir(IndexInput @in)
 {
     if (version >= FSTOrdTermsWriter.TERMS_VERSION_CHECKSUM)
     {
         @in.seek(@in.length() - CodecUtil.footerLength() - 8);
     }
     else
     {
         @in.seek(@in.length() - 8);
     }
     @in.seek(@in.readLong());
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private util.Bits getMissingBits(int fieldNumber, final long offset, final long length) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        private Bits getMissingBits(int fieldNumber, long offset, long length)
        {
            if (offset == -1)
            {
                return(new Bits.MatchAllBits(maxDoc));
            }
            else
            {
                Bits instance;
                lock (this)
                {
                    instance = docsWithFieldInstances[fieldNumber];
                    if (instance == null)
                    {
                        IndexInput data = this.data.clone();
                        data.seek(offset);
                        Debug.Assert(length % 8 == 0);
                        long[] bits = new long[(int)length >> 3];
                        for (int i = 0; i < bits.Length; i++)
                        {
                            bits[i] = data.readLong();
                        }
                        instance = new FixedBitSet(bits, maxDoc);
                        docsWithFieldInstances[fieldNumber] = instance;
                    }
                }
                return(instance);
            }
        }
 public override void lookupOrd(long ord, BytesRef result)
 {
     try
     {
         if (ord < 0 || ord >= field.numValues)
         {
             throw new System.IndexOutOfRangeException("ord must be 0 .. " + (field.numValues - 1) + "; got " + ord);
         }
         @in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.Length + field.maxLength));
         SimpleTextUtil.ReadLine(@in, scratch);
         Debug.Assert(StringHelper.StartsWith(scratch, LENGTH), "got " + scratch.utf8ToString() + " in=" + @in);
         int len;
         try
         {
             len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         result.bytes  = new sbyte[len];
         result.offset = 0;
         result.length = len;
         @in.readBytes(result.bytes, 0, len);
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
 public override bool get(int index)
 {
     try
     {
         @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * index);
         SimpleTextUtil.ReadLine(@in, scratch);
         Debug.Assert(StringHelper.StartsWith(scratch, LENGTH));
         int len;
         try
         {
             len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         // skip past bytes
         sbyte[] bytes = new sbyte[len];
         @in.readBytes(bytes, 0, len);
         SimpleTextUtil.ReadLine(@in, scratch);       // newline
         SimpleTextUtil.ReadLine(@in, scratch);       // 'T' or 'F'
         return(scratch.bytes[scratch.offset] == (sbyte)'T');
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
 public override void get(int docID, BytesRef result)
 {
     try
     {
         if (docID < 0 || docID >= outerInstance.maxDoc)
         {
             throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
         }
         @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * docID);
         SimpleTextUtil.ReadLine(@in, scratch);
         Debug.Assert(StringHelper.StartsWith(scratch, LENGTH));
         int len;
         try
         {
             len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         result.bytes  = new sbyte[len];
         result.offset = 0;
         result.length = len;
         @in.readBytes(result.bytes, 0, len);
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
 public override long get(int docID)
 {
     try
     {
         //System.out.println(Thread.currentThread().getName() + ": get docID=" + docID + " in=" + in);
         if (docID < 0 || docID >= outerInstance.maxDoc)
         {
             throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
         }
         @in.seek(field.dataStartFilePointer + (1 + field.pattern.Length + 2) * docID);
         SimpleTextUtil.ReadLine(@in, scratch);
         //System.out.println("parsing delta: " + scratch.utf8ToString());
         decimal bd;
         try
         {
             bd = (decimal)decoder.parse(scratch.utf8ToString());
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse BigDecimal value (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         SimpleTextUtil.ReadLine(@in, scratch);       // read the line telling us if its real or not
         return(System.Numerics.BigInteger.valueOf(field.minValue) + (long)bd.toBigIntegerExact());
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
Example #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public int nextDoc() throws java.io.IOException
            public override int nextDoc()
            {
                if (++docIt >= upto)
                {
                    return(DocIdSetIterator.NO_MORE_DOCS);
                }
                postingInput.seek(offsets[docIt]);
                currFreq = postingInput.readVInt();
                // reset variables used in nextPosition
                pos = 0;
                endOffset_Renamed = 0;
                return(docs[docIt]);
            }
 public override bool get(int index)
 {
     try
     {
         @in.seek(field.dataStartFilePointer + (1 + field.pattern.Length + 2) * index);
         SimpleTextUtil.ReadLine(@in, scratch);       // data
         SimpleTextUtil.ReadLine(@in, scratch);       // 'T' or 'F'
         return(scratch.bytes[scratch.offset] == (sbyte)'T');
     }
     catch (IOException e)
     {
         throw new Exception(e);
     }
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void checkIntegrity() throws java.io.IOException
        public override void checkIntegrity()
        {
            BytesRef   scratch = new BytesRef();
            IndexInput clone   = data.clone();

            clone.seek(0);
            ChecksumIndexInput input = new BufferedChecksumIndexInput(clone);

            while (true)
            {
                SimpleTextUtil.ReadLine(input, scratch);
                if (scratch.Equals(END))
                {
                    SimpleTextUtil.CheckFooter(input);
                    break;
                }
            }
        }
Example #11
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;
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public SimpleTextDocValuesReader(index.SegmentReadState state, String ext) throws java.io.IOException
        public SimpleTextDocValuesReader(SegmentReadState state, string ext)
        {
            // System.out.println("dir=" + state.directory + " seg=" + state.segmentInfo.name + " file=" + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext));
            data   = state.directory.openInput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
            maxDoc = state.segmentInfo.DocCount;
            while (true)
            {
                readLine();
                //System.out.println("READ field=" + scratch.utf8ToString());
                if (scratch.Equals(END))
                {
                    break;
                }
                Debug.Assert(startsWith(FIELD), scratch.utf8ToString());
                string fieldName = stripPrefix(FIELD);
                //System.out.println("  field=" + fieldName);

                OneField field = new OneField();
                fields[fieldName] = field;

                readLine();
                Debug.Assert(startsWith(TYPE), scratch.utf8ToString());

                FieldInfo.DocValuesType dvType = FieldInfo.DocValuesType.valueOf(stripPrefix(TYPE));
                Debug.Assert(dvType != null);
                if (dvType == FieldInfo.DocValuesType.NUMERIC)
                {
                    readLine();
                    Debug.Assert(startsWith(MINVALUE), "got " + scratch.utf8ToString() + " field=" + fieldName + " ext=" + ext);
                    field.minValue = Convert.ToInt64(stripPrefix(MINVALUE));
                    readLine();
                    Debug.Assert(startsWith(PATTERN));
                    field.pattern = stripPrefix(PATTERN);
                    field.dataStartFilePointer = data.FilePointer;
                    data.seek(data.FilePointer + (1 + field.pattern.Length + 2) * maxDoc);
                }
                else if (dvType == FieldInfo.DocValuesType.BINARY)
                {
                    readLine();
                    Debug.Assert(startsWith(MAXLENGTH));
                    field.maxLength = Convert.ToInt32(stripPrefix(MAXLENGTH));
                    readLine();
                    Debug.Assert(startsWith(PATTERN));
                    field.pattern = stripPrefix(PATTERN);
                    field.dataStartFilePointer = data.FilePointer;
                    data.seek(data.FilePointer + (9 + field.pattern.Length + field.maxLength + 2) * maxDoc);
                }
                else if (dvType == FieldInfo.DocValuesType.SORTED || dvType == FieldInfo.DocValuesType.SORTED_SET)
                {
                    readLine();
                    Debug.Assert(startsWith(NUMVALUES));
                    field.numValues = Convert.ToInt64(stripPrefix(NUMVALUES));
                    readLine();
                    Debug.Assert(startsWith(MAXLENGTH));
                    field.maxLength = Convert.ToInt32(stripPrefix(MAXLENGTH));
                    readLine();
                    Debug.Assert(startsWith(PATTERN));
                    field.pattern = stripPrefix(PATTERN);
                    readLine();
                    Debug.Assert(startsWith(ORDPATTERN));
                    field.ordPattern           = stripPrefix(ORDPATTERN);
                    field.dataStartFilePointer = data.FilePointer;
                    data.seek(data.FilePointer + (9 + field.pattern.Length + field.maxLength) * field.numValues + (1 + field.ordPattern.Length) * maxDoc);
                }
                else
                {
                    throw new AssertionError();
                }
            }

            // We should only be called from above if at least one
            // field has DVs:
            Debug.Assert(fields.Count > 0);
        }
Example #13
0
 public override void seek(long pos)
 {
     _indexInput.seek(pos);
 }