Beispiel #1
0
            public override void Get(int docId, BytesRef result)
            {
                if (docId < 0 || docId >= _outerInstance.MAX_DOC)
                {
                    throw new IndexOutOfRangeException("docID must be 0 .. " + (_outerInstance.MAX_DOC - 1) +
                                                       "; got " + docId);
                }

                _input.Seek(_field.DataStartFilePointer + (9 + _field.Pattern.Length + _field.MaxLength + 2) * docId);
                SimpleTextUtil.ReadLine(_input, _scratch);
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH));
                int len;

                try
                {
                    len = int.Parse(_scratch.Bytes.SubList(
                                        _scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                        _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length).ToString());
                }
                catch (FormatException ex)
                {
                    throw new CorruptIndexException("failed to parse int value (resource=" + _input + ")", ex);
                }

                result.Bytes  = new byte[len];
                result.Offset = 0;
                result.Length = len;
                _input.ReadBytes(result.Bytes, 0, len);
            }
Beispiel #2
0
            public override void LookupOrd(long ord, BytesRef result)
            {
                if (ord < 0 || ord >= _field.NumValues)
                {
                    throw new IndexOutOfRangeException("ord must be 0 .. " + (_field.NumValues - 1) + "; got " + ord);
                }

                _input.Seek(_field.DataStartFilePointer + ord * (9 + _field.Pattern.Length + _field.MaxLength));
                SimpleTextUtil.ReadLine(_input, _scratch);
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH),
                             "got " + _scratch.Utf8ToString() + " in=" + _input);
                int len;

                try
                {
                    len =
                        (int)
                        _decoderFormat.parse(_scratch.Bytes.SubList(
                                                 _scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                                 _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length).ToString());
                }
                catch (Exception pe)
                {
                    var e = new CorruptIndexException("failed to parse int length (resource=" + _input + ")", pe);
                    throw e;
                }

                result.Bytes  = new byte[len];
                result.Offset = 0;
                result.Length = len;
                _input.ReadBytes(result.Bytes, 0, len);
            }
Beispiel #3
0
            public bool Get(int index)
            {
                _input.Seek(_field.DataStartFilePointer + (9 + _field.Pattern.Length + _field.MaxLength + 2) * index);
                SimpleTextUtil.ReadLine(_input, _scratch);
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH));
                int len;

                try
                {
                    len = int.Parse(_scratch.Bytes.SubList(_scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                                           _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length).ToString());
                }
                catch (FormatException ex)
                {
                    throw new CorruptIndexException("failed to parse int value (resource=" + _input + ")", ex);
                }

                // skip past bytes
                var bytes = new byte[len];

                _input.ReadBytes(bytes, 0, len);
                SimpleTextUtil.ReadLine(_input, _scratch); // newline
                SimpleTextUtil.ReadLine(_input, _scratch); // 'T' or 'F'
                return(_scratch.Bytes[_scratch.Offset] == (sbyte)'T');
            }
            public override void Get(int docId, BytesRef result)
            {
                if (docId < 0 || docId >= _outerInstance.MAX_DOC)
                {
                    throw new IndexOutOfRangeException("docID must be 0 .. " + (_outerInstance.MAX_DOC - 1) +
                                                       "; got " + docId);
                }

                _input.Seek(_field.DataStartFilePointer + (9 + _field.Pattern.Length + _field.MaxLength + 2) * docId);
                SimpleTextUtil.ReadLine(_input, _scratch);
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH));
                int len;

                try
                {
                    // LUCNENENET: .NET doesn't have a way to specify a pattern with integer, but all of the standard ones are built in.
                    len = int.Parse(Encoding.UTF8.GetString(_scratch.Bytes, _scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                                            _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length), NumberStyles.Integer, CultureInfo.InvariantCulture);
                }
                catch (FormatException ex)
                {
                    throw new CorruptIndexException("failed to parse int value (resource=" + _input + ")", ex);
                }

                result.Bytes  = new byte[len];
                result.Offset = 0;
                result.Length = len;
                _input.ReadBytes(result.Bytes, 0, len);
            }
            public override void LookupOrd(long ord, BytesRef result)
            {
                if (ord < 0 || ord >= _field.NumValues)
                {
                    throw new IndexOutOfRangeException("ord must be 0 .. " + (_field.NumValues - 1) + "; got " + ord);
                }

                _input.Seek(_field.DataStartFilePointer + ord * (9 + _field.Pattern.Length + _field.MaxLength));
                SimpleTextUtil.ReadLine(_input, _scratch);
                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH),
                             "got " + _scratch.Utf8ToString() + " in=" + _input);
                int len;

                try
                {
                    // LUCNENENET: .NET doesn't have a way to specify a pattern with integer, but all of the standard ones are built in.
                    len = int.Parse(Encoding.UTF8.GetString(_scratch.Bytes, _scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                                            _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length), NumberStyles.Integer, CultureInfo.InvariantCulture);
                }
                catch (Exception pe)
                {
                    var e = new CorruptIndexException("failed to parse int length (resource=" + _input + ")", pe);
                    throw e;
                }

                result.Bytes  = new byte[len];
                result.Offset = 0;
                result.Length = len;
                _input.ReadBytes(result.Bytes, 0, len);
            }
            public override void LookupOrd(long ord, BytesRef result)
            {
                if (ord < 0 || ord >= field.NumValues)
                {
                    throw new 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, SimpleTextDocValuesWriter.LENGTH),
                             "got " + scratch.Utf8ToString() + " in=" + @in);
                int len;

                try
                {
                    len =
                        (int)
                        decoder.parse(scratch.Bytes.SubList(
                                          scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                          scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length).ToString());
                }
                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);
            }