private void ReadFields(IndexInput meta /*, FieldInfos infos // LUCENENET: Not read */)
        {
            int fieldNumber = meta.ReadVInt32();

            while (fieldNumber != -1)
            {
                // check should be: infos.fieldInfo(fieldNumber) != null, which incorporates negative check
                // but docvalues updates are currently buggy here (loading extra stuff, etc): LUCENE-5616
                if (fieldNumber < 0)
                {
                    // trickier to validate more: because we re-use for norms, because we use multiple entries
                    // for "composite" types like sortedset, etc.
                    throw new CorruptIndexException("Invalid field number: " + fieldNumber + " (resource=" + meta + ")");
                }
                byte type = meta.ReadByte();
                if (type == Lucene45DocValuesFormat.NUMERIC)
                {
                    numerics[fieldNumber] = ReadNumericEntry(meta);
                }
                else if (type == Lucene45DocValuesFormat.BINARY)
                {
                    BinaryEntry b = ReadBinaryEntry(meta);
                    binaries[fieldNumber] = b;
                }
                else if (type == Lucene45DocValuesFormat.SORTED)
                {
                    ReadSortedField(fieldNumber, meta /*, infos // LUCENENET: Never read */);
                }
                else if (type == Lucene45DocValuesFormat.SORTED_SET)
                {
                    SortedSetEntry ss = ReadSortedSetEntry(meta);
                    sortedSets[fieldNumber] = ss;
                    if (ss.Format == Lucene45DocValuesConsumer.SORTED_SET_WITH_ADDRESSES)
                    {
                        ReadSortedSetFieldWithAddresses(fieldNumber, meta /*, infos // LUCENENET: Never read */);
                    }
                    else if (ss.Format == Lucene45DocValuesConsumer.SORTED_SET_SINGLE_VALUED_SORTED)
                    {
                        if (meta.ReadVInt32() != fieldNumber)
                        {
                            throw new CorruptIndexException("sortedset entry for field: " + fieldNumber + " is corrupt (resource=" + meta + ")");
                        }
                        if (meta.ReadByte() != Lucene45DocValuesFormat.SORTED)
                        {
                            throw new CorruptIndexException("sortedset entry for field: " + fieldNumber + " is corrupt (resource=" + meta + ")");
                        }
                        ReadSortedField(fieldNumber, meta /*, infos // LUCENENET: Never read */);
                    }
                    else
                    {
                        throw AssertionError.Create();
                    }
                }
                else
                {
                    throw new CorruptIndexException("invalid type: " + type + ", resource=" + meta);
                }
                fieldNumber = meta.ReadVInt32();
            }
        }
Beispiel #2
0
        public override BinaryDocValues GetBinary(FieldInfo field)
        {
            lock (this)
            {
                if (!binaryInstances.TryGetValue(field.Number, out BinaryDocValues instance))
                {
                    var type = field.GetAttribute(legacyKey).ToLegacyDocValuesType();

                    if (type == LegacyDocValuesType.BYTES_FIXED_STRAIGHT)
                    {
                        instance = LoadBytesFixedStraight(field);
                    }
                    else if (type == LegacyDocValuesType.BYTES_VAR_STRAIGHT)
                    {
                        instance = LoadBytesVarStraight(field);
                    }
                    else if (type == LegacyDocValuesType.BYTES_FIXED_DEREF)
                    {
                        instance = LoadBytesFixedDeref(field);
                    }
                    else if (type == LegacyDocValuesType.BYTES_VAR_DEREF)
                    {
                        instance = LoadBytesVarDeref(field);
                    }
                    else
                    {
                        throw AssertionError.Create();
                    }
                    binaryInstances[field.Number] = instance;
                }
                return(instance);
            }
        }
        internal virtual Int64Values GetNumeric(NumericEntry entry)
        {
            IndexInput data = (IndexInput)this.data.Clone();

            data.Seek(entry.Offset);

            switch (entry.format)
            {
            case Lucene45DocValuesConsumer.DELTA_COMPRESSED:
                BlockPackedReader reader = new BlockPackedReader(data, entry.PackedInt32sVersion, entry.BlockSize, entry.Count, true);
                return(reader);

            case Lucene45DocValuesConsumer.GCD_COMPRESSED:
                long min  = entry.minValue;
                long mult = entry.gcd;
                BlockPackedReader quotientReader = new BlockPackedReader(data, entry.PackedInt32sVersion, entry.BlockSize, entry.Count, true);
                return(new Int64ValuesAnonymousClass(min, mult, quotientReader));

            case Lucene45DocValuesConsumer.TABLE_COMPRESSED:
                long[] table             = entry.table;
                int    bitsRequired      = PackedInt32s.BitsRequired(table.Length - 1);
                PackedInt32s.Reader ords = PackedInt32s.GetDirectReaderNoHeader(data, PackedInt32s.Format.PACKED, entry.PackedInt32sVersion, (int)entry.Count, bitsRequired);
                return(new Int64ValuesAnonymousClass2(table, ords));

            default:
                throw AssertionError.Create();
            }
        }
 private static sbyte DocValuesByte(DocValuesType type)
 {
     if (type == DocValuesType.NONE)
     {
         return(0);
     }
     else if (type == DocValuesType.NUMERIC)
     {
         return(1);
     }
     else if (type == DocValuesType.BINARY)
     {
         return(2);
     }
     else if (type == DocValuesType.SORTED)
     {
         return(3);
     }
     else if (type == DocValuesType.SORTED_SET)
     {
         return(4);
     }
     else
     {
         throw AssertionError.Create();
     }
 }
Beispiel #5
0
        private static void LoopRunTest(Fixture fixture, int testRuns)
        {
            IList <Exception> exceptionList = new List <Exception>();

            LoopRun(fixture, testRuns, exceptionList);

            if (exceptionList.Count > 0)
            {
                // We saw exceptions. Run it 99 more times, and then verify that our false deadlock rate is less than 2%.
                int additionalRuns = testRuns * 99;
                LoopRun(fixture, additionalRuns, exceptionList);
                double totalRuns   = additionalRuns + testRuns;
                double failures    = exceptionList.Count;
                double failureRate = failures / totalRuns;
                if (failureRate > 0.02)
                {
                    // We have more than 2% failures. Report it!
                    AssertionError error = new AssertionError("False deadlock failure rate of " + failureRate + " is greater than 2%");
                    foreach (Exception th in exceptionList)
                    {
                        error.addSuppressed(th);
                    }
                    throw error;
                }
            }
        }
Beispiel #6
0
 protected virtual void Recompose(IList <SrndQuery> queries)
 {
     if (queries.Count < 2)
     {
         throw AssertionError.Create("Too few subqueries");
     }
     this.m_queries = new JCG.List <SrndQuery>(queries);
 }
Beispiel #7
0
        public override SortedDocValues GetSorted(FieldInfo field)
        {
            UninterruptableMonitor.Enter(this);
            try
            {
                if (!sortedInstances.TryGetValue(field.Number, out SortedDocValues instance))
                {
                    string     dataName  = IndexFileNames.SegmentFileName(state.SegmentInfo.Name + "_" + Convert.ToString(field.Number, CultureInfo.InvariantCulture), segmentSuffix, "dat");
                    string     indexName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name + "_" + Convert.ToString(field.Number, CultureInfo.InvariantCulture), segmentSuffix, "idx");
                    IndexInput data      = null;
                    IndexInput index     = null;
                    bool       success   = false;
                    try
                    {
                        data  = dir.OpenInput(dataName, state.Context);
                        index = dir.OpenInput(indexName, state.Context);

                        var type = field.GetAttribute(legacyKey).ToLegacyDocValuesType();

                        if (type == LegacyDocValuesType.BYTES_FIXED_SORTED)
                        {
                            instance = LoadBytesFixedSorted(/* field, // LUCENENET: Never read */ data, index);
                        }
                        else if (type == LegacyDocValuesType.BYTES_VAR_SORTED)
                        {
                            instance = LoadBytesVarSorted(/* field, // LUCENENET: Never read */ data, index);
                        }
                        else
                        {
                            throw AssertionError.Create();
                        }

                        CodecUtil.CheckEOF(data);
                        CodecUtil.CheckEOF(index);
                        success = true;
                    }
                    finally
                    {
                        if (success)
                        {
                            IOUtils.Dispose(data, index);
                        }
                        else
                        {
                            IOUtils.DisposeWhileHandlingException(data, index);
                        }
                    }
                    sortedInstances[field.Number] = instance;
                }
                return(instance);
            }
            finally
            {
                UninterruptableMonitor.Exit(this);
            }
        }
 public override void Merge(IndexWriter writer, MergeTrigger trigger, bool newMergesFound)
 {
     lock (this)
     {
         if (!mayMerge.Value && writer.NextMerge() != null)
         {
             throw AssertionError.Create();
         }
         base.Merge(writer, trigger, newMergesFound);
     }
 }
Beispiel #9
0
        private NumericDocValues LoadNumeric(FieldInfo field)
        {
            NumericEntry entry = numerics[field.Number];

            data.Seek(entry.offset + entry.missingBytes);
            switch (entry.format)
            {
            case TABLE_COMPRESSED:
                int size = data.ReadVInt32();
                if (size > 256)
                {
                    throw new CorruptIndexException(
                              "TABLE_COMPRESSED cannot have more than 256 distinct values, input=" + data);
                }
                var decode = new long[size];
                for (int i = 0; i < decode.Length; i++)
                {
                    decode[i] = data.ReadInt64();
                }
                int formatID     = data.ReadVInt32();
                int bitsPerValue = data.ReadVInt32();
                var ordsReader   = PackedInt32s.GetReaderNoHeader(data, PackedInt32s.Format.ById(formatID),
                                                                  entry.packedIntsVersion, maxDoc, bitsPerValue);
                ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(decode) + ordsReader.RamBytesUsed());
                return(new NumericDocValuesAnonymousClass(decode, ordsReader));

            case DELTA_COMPRESSED:
                int blockSize = data.ReadVInt32();
                var reader    = new BlockPackedReader(data, entry.packedIntsVersion, blockSize, maxDoc,
                                                      false);
                ramBytesUsed.AddAndGet(reader.RamBytesUsed());
                return(reader);

            case UNCOMPRESSED:
                var bytes = new byte[maxDoc];
                data.ReadBytes(bytes, 0, bytes.Length);
                ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(bytes));
                // LUCENENET: IMPORTANT - some bytes are negative here, so we need to pass as sbyte
                return(new NumericDocValuesAnonymousClass2((sbyte[])(Array)bytes));

            case GCD_COMPRESSED:
                long min  = data.ReadInt64();
                long mult = data.ReadInt64();
                int  quotientBlockSize = data.ReadVInt32();
                var  quotientReader    = new BlockPackedReader(data, entry.packedIntsVersion,
                                                               quotientBlockSize, maxDoc, false);
                ramBytesUsed.AddAndGet(quotientReader.RamBytesUsed());
                return(new NumericDocValuesAnonymousClass3(min, mult, quotientReader));

            default:
                throw AssertionError.Create();
            }
        }
Beispiel #10
0
 public virtual void AddSpanQuery(Search.Query q)
 {
     if (q == SrndQuery.TheEmptyLcnQuery)
     {
         return;
     }
     if (!(q is SpanQuery))
     {
         throw AssertionError.Create("Expected SpanQuery: " + q.ToString(FieldName));
     }
     AddSpanQueryWeighted((SpanQuery)q, q.Boost);
 }
 public override T Apply(GraphDatabaseService graphDb)
 {
     try
     {
         return(Perform(graphDb));
     }
     catch (AssertionError e)
     {
         AssertionError error = new AssertionError(Message + ": " + e.Message);
         error.StackTrace = e.StackTrace;
         throw error;
     }
 }
Beispiel #12
0
        public static Search.Query MakeBooleanQuery(
            IList <Search.Query> queries,
            Occur occur)
        {
            if (queries.Count <= 1)
            {
                throw AssertionError.Create("Too few subqueries: " + queries.Count);
            }
            BooleanQuery bq = new BooleanQuery();

            AddQueriesToBoolean(bq, queries, occur);
            return(bq);
        }
        private NumericDocValues LoadNumeric(NumericEntry entry)
        {
            data.Seek(entry.offset + entry.missingBytes);
            switch (entry.byteWidth)
            {
            case 1:
            {
                var values = new byte[entry.count];
                data.ReadBytes(values, 0, entry.count);
                ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
                // LUCENENET: IMPORTANT - some bytes are negative here, so we need to pass as sbyte
                return(new NumericDocValuesAnonymousClass((sbyte[])(Array)values));
            }

            case 2:
            {
                var values = new short[entry.count];
                for (int i = 0; i < entry.count; i++)
                {
                    values[i] = data.ReadInt16();
                }
                ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
                return(new NumericDocValuesAnonymousClass2(values));
            }

            case 4:
            {
                var values = new int[entry.count];
                for (var i = 0; i < entry.count; i++)
                {
                    values[i] = data.ReadInt32();
                }
                ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
                return(new NumericDocValuesAnonymousClass3(values));
            }

            case 8:
            {
                var values = new long[entry.count];
                for (int i = 0; i < entry.count; i++)
                {
                    values[i] = data.ReadInt64();
                }
                ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
                return(new NumericDocValuesAnonymousClass4(values));
            }

            default:
                throw AssertionError.Create();
            }
        }
Beispiel #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static synchronized org.neo4j.server.NeoServer allocate() throws java.io.IOException
        internal static NeoServer Allocate()
        {
            lock (typeof(ServerHolder))
            {
                if (_allocation != null)
                {
                    throw _allocation;
                }
                if (_server == null)
                {
                    _server = StartServer();
                }
                _allocation = new AssertionError("The server was allocated from here but not released properly");
                return(_server);
            }
        }
Beispiel #15
0
 public override void Merge(IndexWriter writer, MergeTrigger trigger, bool newMergesFound)
 {
     UninterruptableMonitor.Enter(this);
     try
     {
         if (!mayMerge.Value && writer.NextMerge() != null)
         {
             throw AssertionError.Create();
         }
         base.Merge(writer, trigger, newMergesFound);
     }
     finally
     {
         UninterruptableMonitor.Exit(this);
     }
 }
Beispiel #16
0
 internal virtual void WriteSequence()
 {
     if (Debugging.AssertsEnabled)
     {
         Debugging.Assert(SequenceIsConsistent());
     }
     try
     {
         WriteHeader(reverse, clean, dirtyWords.Length);
     }
     catch (Exception cannotHappen) when(cannotHappen.IsIOException())
     {
         throw AssertionError.Create(cannotHappen.Message, cannotHappen);
     }
     @out.WriteBytes(dirtyWords.Bytes, 0, dirtyWords.Length);
     dirtyWords.Length = 0;
     ++numSequences;
 }
Beispiel #17
0
            protected override SortedDocValues GetSortedDocValues(AtomicReaderContext context, string field)
            {
                SortedSetDocValues sortedSet = FieldCache.DEFAULT.GetDocTermOrds(context.AtomicReader, field);

                if (sortedSet.ValueCount >= int.MaxValue)
                {
                    throw UnsupportedOperationException.Create("fields containing more than " + (int.MaxValue - 1) + " unique terms are unsupported");
                }

                SortedDocValues singleton = DocValues.UnwrapSingleton(sortedSet);

                if (singleton != null)
                {
                    // it's actually single-valued in practice, but indexed as multi-valued,
                    // so just sort on the underlying single-valued dv directly.
                    // regardless of selector type, this optimization is safe!
                    return(singleton);
                }
                else if (outerInstance.selector == Selector.MIN)
                {
                    return(new MinValue(sortedSet));
                }
                else
                {
                    if (sortedSet is RandomAccessOrds == false)
                    {
                        throw UnsupportedOperationException.Create("codec does not support random access ordinals, cannot use selector: " + outerInstance.selector);
                    }
                    RandomAccessOrds randomOrds = (RandomAccessOrds)sortedSet;
                    switch (outerInstance.selector)
                    {
                    case Selector.MAX: return(new MaxValue(randomOrds));

                    case Selector.MIDDLE_MIN: return(new MiddleMinValue(randomOrds));

                    case Selector.MIDDLE_MAX: return(new MiddleMaxValue(randomOrds));

                    case Selector.MIN:
                    default:
                        throw AssertionError.Create();
                    }
                }
            }
        public override BinaryDocValues GetBinary(FieldInfo field)
        {
            BinaryEntry bytes = binaries[field.Number];

            switch (bytes.format)
            {
            case Lucene45DocValuesConsumer.BINARY_FIXED_UNCOMPRESSED:
                return(GetFixedBinary(/*field, LUCENENET: Never read */ bytes));

            case Lucene45DocValuesConsumer.BINARY_VARIABLE_UNCOMPRESSED:
                return(GetVariableBinary(field, bytes));

            case Lucene45DocValuesConsumer.BINARY_PREFIX_COMPRESSED:
                return(GetCompressedBinary(field, bytes));

            default:
                throw AssertionError.Create();
            }
        }
Beispiel #19
0
            internal Field GetNumericField(string name, NumericType type)
            {
                Field f;

                if (reuseFields)
                {
                    numericFields.TryGetValue(name, out f);
                }
                else
                {
                    f = null;
                }

                if (f == null)
                {
                    switch (type)
                    {
                    case NumericType.INT32:
                        f = new Int32Field(name, 0, Field.Store.NO);
                        break;

                    case NumericType.INT64:
                        f = new Int64Field(name, 0L, Field.Store.NO);
                        break;

                    case NumericType.SINGLE:
                        f = new SingleField(name, 0.0F, Field.Store.NO);
                        break;

                    case NumericType.DOUBLE:
                        f = new DoubleField(name, 0.0, Field.Store.NO);
                        break;

                    default:
                        throw AssertionError.Create("Cannot get here");
                    }
                    if (reuseFields)
                    {
                        numericFields[name] = f;
                    }
                }
                return(f);
            }
Beispiel #20
0
 internal static void Release(NeoServer server)
 {
     lock (typeof(ServerHolder))
     {
         if (server == null)
         {
             return;
         }
         if (server != ServerHolder._server)
         {
             throw new AssertionError("trying to suspend a server not allocated from here");
         }
         if (_allocation == null)
         {
             throw new AssertionError("releasing the server although it is not allocated");
         }
         _allocation = null;
     }
 }
Beispiel #21
0
 private static void Shutdown()
 {
     lock (typeof(ServerHolder))
     {
         _allocation = null;
         try
         {
             if (_server != null)
             {
                 _server.stop();
             }
         }
         finally
         {
             _builder = null;
             _server  = null;
         }
     }
 }
        public override IBits GetDocsWithField(FieldInfo field)
        {
            switch (field.DocValuesType)
            {
            case DocValuesType.SORTED_SET:
                return(DocValues.DocsWithValue(GetSortedSet(field), maxDoc));

            case DocValuesType.SORTED:
                return(DocValues.DocsWithValue(GetSorted(field), maxDoc));

            case DocValuesType.BINARY:
                return(GetBinaryDocsWithField(field));

            case DocValuesType.NUMERIC:
                return(GetNumericDocsWithField(field));

            default:
                throw AssertionError.Create();
            }
        }
Beispiel #23
0
        /// <summary>
        /// Create a random instance.
        /// </summary>
        public static CompressingCodec RandomInstance(Random random, int chunkSize, bool withSegmentSuffix)
        {
            switch (random.Next(4))
            {
            case 0:
                return(new FastCompressingCodec(chunkSize, withSegmentSuffix));

            case 1:
                return(new FastDecompressionCompressingCodec(chunkSize, withSegmentSuffix));

            case 2:
                return(new HighCompressionCompressingCodec(chunkSize, withSegmentSuffix));

            case 3:
                return(new DummyCompressingCodec(chunkSize, withSegmentSuffix));

            default:
                throw AssertionError.Create();
            }
        }
Beispiel #24
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"));
            }
        }
        public override IBits GetDocsWithField(FieldInfo field)
        {
            switch (field.DocValuesType)
            {
            case DocValuesType.SORTED_SET:
                return(DocValues.DocsWithValue(GetSortedSet(field), maxDoc));

            case DocValuesType.SORTED:
                return(DocValues.DocsWithValue(GetSorted(field), maxDoc));

            case DocValuesType.BINARY:
                BinaryEntry be = binaries[field.Number];
                return(GetMissingBits(field.Number, be.missingOffset, be.missingBytes));

            case DocValuesType.NUMERIC:
                NumericEntry ne = numerics[field.Number];
                return(GetMissingBits(field.Number, ne.missingOffset, ne.missingBytes));

            default:
                throw AssertionError.Create();
            }
        }
Beispiel #26
0
        private static void ThrowBadAccess(long pointer, int size, KeyValuePair <long, Allocation> fentry, KeyValuePair <long, Allocation> centry)
        {
            long now                      = System.nanoTime();
            long faddr                    = fentry == null ? 0 : fentry.Key;
            long fsize                    = fentry == null ? 0 : fentry.Value.sizeInBytes;
            long foffset                  = pointer - (faddr + fsize);
            long caddr                    = centry == null ? 0 : centry.Key;
            long csize                    = centry == null ? 0 : centry.Value.sizeInBytes;
            long coffset                  = caddr - (pointer + size);
            bool floorIsNearest           = foffset < coffset;
            long naddr                    = floorIsNearest ? faddr : caddr;
            long nsize                    = floorIsNearest ? fsize : csize;
            long noffset                  = floorIsNearest ? foffset : coffset;
            IList <FreeTrace> recentFrees = java.util.freeTraces.Where(Objects.nonNull).Where(trace => trace.contains(pointer)).OrderBy(c => c).ToList();
            AssertionError    error       = new AssertionError(format("Bad access to address 0x%x with size %s, nearest valid allocation is " + "0x%x (%s bytes, off by %s bytes). " + "Recent relevant frees (of %s) are attached as suppressed exceptions.", pointer, size, naddr, nsize, noffset, _freeCounter.get()));

            foreach (FreeTrace recentFree in recentFrees)
            {
                recentFree.ReferenceTime = now;
                error.addSuppressed(recentFree);
            }
            throw error;
        }
Beispiel #27
0
 public static BulkOperation Of(PackedInt32s.Format format, int bitsPerValue)
 {
     if (format == PackedInt32s.Format.PACKED)
     {
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(packedBulkOps[bitsPerValue - 1] != null);
         }
         return(packedBulkOps[bitsPerValue - 1]);
     }
     else if (format == PackedInt32s.Format.PACKED_SINGLE_BLOCK)
     {
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(packedSingleBlockBulkOps[bitsPerValue - 1] != null);
         }
         return(packedSingleBlockBulkOps[bitsPerValue - 1]);
     }
     else
     {
         throw AssertionError.Create();
     }
 }
Beispiel #28
0
        private static void SkipField(DataInput @in, int bits)
        {
            switch (bits & CompressingStoredFieldsWriter.TYPE_MASK)
            {
            case CompressingStoredFieldsWriter.BYTE_ARR:
            case CompressingStoredFieldsWriter.STRING:
                int length = @in.ReadVInt32();
                @in.SkipBytes(length);
                break;

            case CompressingStoredFieldsWriter.NUMERIC_INT32:
            case CompressingStoredFieldsWriter.NUMERIC_SINGLE:
                @in.ReadInt32();
                break;

            case CompressingStoredFieldsWriter.NUMERIC_INT64:
            case CompressingStoredFieldsWriter.NUMERIC_DOUBLE:
                @in.ReadInt64();
                break;

            default:
                throw AssertionError.Create("Unknown type flag: " + bits.ToString("x"));
            }
        }
        public override SortedSetDocValues GetSortedSet(FieldInfo field)
        {
            SortedSetEntry ss = sortedSets[field.Number];

            if (ss.Format == Lucene45DocValuesConsumer.SORTED_SET_SINGLE_VALUED_SORTED)
            {
                SortedDocValues values = GetSorted(field);
                return(DocValues.Singleton(values));
            }
            else if (ss.Format != Lucene45DocValuesConsumer.SORTED_SET_WITH_ADDRESSES)
            {
                throw AssertionError.Create();
            }

            IndexInput data       = (IndexInput)this.data.Clone();
            long       valueCount = binaries[field.Number].Count;
            // we keep the byte[]s and list of ords on disk, these could be large
            Int64BinaryDocValues binary   = (Int64BinaryDocValues)GetBinary(field);
            Int64Values          ordinals = GetNumeric(ords[field.Number]);
            // but the addresses to the ord stream are in RAM
            MonotonicBlockPackedReader ordIndex = GetOrdIndexInstance(data, field, ordIndexes[field.Number]);

            return(new RandomAccessOrdsAnonymousClass(valueCount, binary, ordinals, ordIndex));
        }
Beispiel #30
0
        public override void WriteField(FieldInfo info, IIndexableField field)
        {
            int      bits /* = 0*/; // LUCENENET: IDE0059: Remove unnecessary value assignment
            BytesRef bytes;
            string   @string;

            // LUCENENET specific - To avoid boxing/unboxing, we don't
            // call GetNumericValue(). Instead, we check the field.NumericType and then
            // call the appropriate conversion method.
            if (field.NumericType != NumericFieldType.NONE)
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    bits = NUMERIC_INT32;
                    break;

                case NumericFieldType.INT64:
                    bits = NUMERIC_INT64;
                    break;

                case NumericFieldType.SINGLE:
                    bits = NUMERIC_SINGLE;
                    break;

                case NumericFieldType.DOUBLE:
                    bits = NUMERIC_DOUBLE;
                    break;

                default:
                    throw new ArgumentException("cannot store numeric type " + field.NumericType);
                }

                @string = null;
                bytes   = null;
            }
            else
            {
                bytes = field.GetBinaryValue();
                if (bytes != null)
                {
                    bits    = BYTE_ARR;
                    @string = null;
                }
                else
                {
                    bits    = STRING;
                    @string = field.GetStringValue();
                    if (@string == null)
                    {
                        throw new ArgumentException("field " + field.Name + " is stored but does not have BinaryValue, StringValue nor NumericValue");
                    }
                }
            }

            long infoAndBits = (((long)info.Number) << TYPE_BITS) | (uint)bits;

            bufferedDocs.WriteVInt64(infoAndBits);

            if (bytes != null)
            {
                bufferedDocs.WriteVInt32(bytes.Length);
                bufferedDocs.WriteBytes(bytes.Bytes, bytes.Offset, bytes.Length);
            }
            else if (@string != null)
            {
                bufferedDocs.WriteString(field.GetStringValue());
            }
            else
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    bufferedDocs.WriteInt32(field.GetInt32Value().Value);
                    break;

                case NumericFieldType.INT64:
                    bufferedDocs.WriteInt64(field.GetInt64Value().Value);
                    break;

                case NumericFieldType.SINGLE:
                    bufferedDocs.WriteInt32(BitConversion.SingleToInt32Bits(field.GetSingleValue().Value));
                    break;

                case NumericFieldType.DOUBLE:
                    bufferedDocs.WriteInt64(BitConversion.DoubleToInt64Bits(field.GetDoubleValue().Value));
                    break;

                default:
                    throw AssertionError.Create("Cannot get here");
                }
            }
        }