Search in sources :

Example 6 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class Lucene70DocValuesProducer method getSorted.

private SortedDocValues getSorted(SortedEntry entry) throws IOException {
    if (entry.docsWithFieldOffset == -2) {
        return DocValues.emptySorted();
    }
    final LongValues ords;
    if (entry.bitsPerValue == 0) {
        ords = new LongValues() {

            @Override
            public long get(long index) {
                return 0L;
            }
        };
    } else {
        final RandomAccessInput slice = data.randomAccessSlice(entry.ordsOffset, entry.ordsLength);
        ords = DirectReader.getInstance(slice, entry.bitsPerValue);
    }
    if (entry.docsWithFieldOffset == -1) {
        // dense
        return new BaseSortedDocValues(entry, data) {

            int doc = -1;

            @Override
            public int nextDoc() throws IOException {
                return advance(doc + 1);
            }

            @Override
            public int docID() {
                return doc;
            }

            @Override
            public long cost() {
                return maxDoc;
            }

            @Override
            public int advance(int target) throws IOException {
                if (target >= maxDoc) {
                    return doc = NO_MORE_DOCS;
                }
                return doc = target;
            }

            @Override
            public boolean advanceExact(int target) {
                doc = target;
                return true;
            }

            @Override
            public int ordValue() {
                return (int) ords.get(doc);
            }
        };
    } else {
        // sparse
        final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
        return new BaseSortedDocValues(entry, data) {

            @Override
            public int nextDoc() throws IOException {
                return disi.nextDoc();
            }

            @Override
            public int docID() {
                return disi.docID();
            }

            @Override
            public long cost() {
                return disi.cost();
            }

            @Override
            public int advance(int target) throws IOException {
                return disi.advance(target);
            }

            @Override
            public boolean advanceExact(int target) throws IOException {
                return disi.advanceExact(target);
            }

            @Override
            public int ordValue() {
                return (int) ords.get(disi.index());
            }
        };
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) LongValues(org.apache.lucene.util.LongValues)

Example 7 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class Lucene70DocValuesProducer method getSortedSet.

@Override
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
    SortedSetEntry entry = sortedSets.get(field.name);
    if (entry.singleValueEntry != null) {
        return DocValues.singleton(getSorted(entry.singleValueEntry));
    }
    final RandomAccessInput slice = data.randomAccessSlice(entry.ordsOffset, entry.ordsLength);
    final LongValues ords = DirectReader.getInstance(slice, entry.bitsPerValue);
    final RandomAccessInput addressesInput = data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
    final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
    if (entry.docsWithFieldOffset == -1) {
        // dense
        return new BaseSortedSetDocValues(entry, data) {

            int doc = -1;

            long start;

            long end;

            @Override
            public int nextDoc() throws IOException {
                return advance(doc + 1);
            }

            @Override
            public int docID() {
                return doc;
            }

            @Override
            public long cost() {
                return maxDoc;
            }

            @Override
            public int advance(int target) throws IOException {
                if (target >= maxDoc) {
                    return doc = NO_MORE_DOCS;
                }
                start = addresses.get(target);
                end = addresses.get(target + 1L);
                return doc = target;
            }

            @Override
            public boolean advanceExact(int target) throws IOException {
                start = addresses.get(target);
                end = addresses.get(target + 1L);
                doc = target;
                return true;
            }

            @Override
            public long nextOrd() throws IOException {
                if (start == end) {
                    return NO_MORE_ORDS;
                }
                return ords.get(start++);
            }
        };
    } else {
        // sparse
        final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
        return new BaseSortedSetDocValues(entry, data) {

            boolean set;

            long start;

            long end = 0;

            @Override
            public int nextDoc() throws IOException {
                set = false;
                return disi.nextDoc();
            }

            @Override
            public int docID() {
                return disi.docID();
            }

            @Override
            public long cost() {
                return disi.cost();
            }

            @Override
            public int advance(int target) throws IOException {
                set = false;
                return disi.advance(target);
            }

            @Override
            public boolean advanceExact(int target) throws IOException {
                set = false;
                return disi.advanceExact(target);
            }

            @Override
            public long nextOrd() throws IOException {
                if (set == false) {
                    final int index = disi.index();
                    final long start = addresses.get(index);
                    this.start = start + 1;
                    end = addresses.get(index + 1L);
                    set = true;
                    return ords.get(start);
                } else if (start == end) {
                    return NO_MORE_ORDS;
                } else {
                    return ords.get(start++);
                }
            }
        };
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) LongValues(org.apache.lucene.util.LongValues)

Example 8 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class Lucene70DocValuesProducer method getNumericValues.

private LongValues getNumericValues(NumericEntry entry) throws IOException {
    if (entry.bitsPerValue == 0) {
        return new LongValues() {

            @Override
            public long get(long index) {
                return entry.minValue;
            }
        };
    } else {
        final RandomAccessInput slice = data.randomAccessSlice(entry.valuesOffset, entry.valuesLength);
        if (entry.blockShift >= 0) {
            final int shift = entry.blockShift;
            final long mul = entry.gcd;
            final long mask = (1L << shift) - 1;
            return new LongValues() {

                long block = -1;

                long delta;

                long offset;

                long blockEndOffset;

                LongValues values;

                public long get(long index) {
                    final long block = index >>> shift;
                    if (this.block != block) {
                        assert block > this.block : "Reading backwards is illegal: " + this.block + " < " + block;
                        int bitsPerValue;
                        do {
                            offset = blockEndOffset;
                            try {
                                bitsPerValue = slice.readByte(offset++);
                                delta = slice.readLong(offset);
                                offset += Long.BYTES;
                                if (bitsPerValue == 0) {
                                    blockEndOffset = offset;
                                } else {
                                    final int length = slice.readInt(offset);
                                    offset += Integer.BYTES;
                                    blockEndOffset = offset + length;
                                }
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                            this.block++;
                        } while (this.block != block);
                        values = bitsPerValue == 0 ? LongValues.ZEROES : DirectReader.getInstance(slice, bitsPerValue, offset);
                    }
                    return mul * values.get(index & mask) + delta;
                }
            };
        } else {
            final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
            if (entry.table != null) {
                final long[] table = entry.table;
                return new LongValues() {

                    @Override
                    public long get(long index) {
                        return table[(int) values.get(index)];
                    }
                };
            } else if (entry.gcd != 1) {
                final long gcd = entry.gcd;
                final long minValue = entry.minValue;
                return new LongValues() {

                    @Override
                    public long get(long index) {
                        return values.get(index) * gcd + minValue;
                    }
                };
            } else if (entry.minValue != 0) {
                final long minValue = entry.minValue;
                return new LongValues() {

                    @Override
                    public long get(long index) {
                        return values.get(index) + minValue;
                    }
                };
            } else {
                return values;
            }
        }
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) LongValues(org.apache.lucene.util.LongValues) IOException(java.io.IOException)

Example 9 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class Lucene54DocValuesProducer method getNumeric.

LongValues getNumeric(NumericEntry entry) throws IOException {
    switch(entry.format) {
        case CONST_COMPRESSED:
            {
                final long constant = entry.minValue;
                final Bits live = getLiveBits(entry.missingOffset, (int) entry.count);
                return new LongValues() {

                    @Override
                    public long get(long index) {
                        return live.get((int) index) ? constant : 0;
                    }
                };
            }
        case DELTA_COMPRESSED:
            {
                RandomAccessInput slice = this.data.randomAccessSlice(entry.offset, entry.endOffset - entry.offset);
                final long delta = entry.minValue;
                final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue, 0);
                return new LongValues() {

                    @Override
                    public long get(long id) {
                        return delta + values.get(id);
                    }
                };
            }
        case GCD_COMPRESSED:
            {
                RandomAccessInput slice = this.data.randomAccessSlice(entry.offset, entry.endOffset - entry.offset);
                final long min = entry.minValue;
                final long mult = entry.gcd;
                final LongValues quotientReader = DirectReader.getInstance(slice, entry.bitsPerValue, 0);
                return new LongValues() {

                    @Override
                    public long get(long id) {
                        return min + mult * quotientReader.get(id);
                    }
                };
            }
        case TABLE_COMPRESSED:
            {
                RandomAccessInput slice = this.data.randomAccessSlice(entry.offset, entry.endOffset - entry.offset);
                final long[] table = entry.table;
                final LongValues ords = DirectReader.getInstance(slice, entry.bitsPerValue, 0);
                return new LongValues() {

                    @Override
                    public long get(long id) {
                        return table[(int) ords.get(id)];
                    }
                };
            }
        case SPARSE_COMPRESSED:
            final SparseNumericDocValues values = getSparseNumericDocValues(entry);
            final long missingValue;
            switch(entry.numberType) {
                case ORDINAL:
                    missingValue = -1L;
                    break;
                case VALUE:
                    missingValue = 0L;
                    break;
                default:
                    throw new AssertionError();
            }
            return new SparseNumericDocValuesRandomAccessWrapper(values, missingValue);
        default:
            throw new AssertionError();
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) Bits(org.apache.lucene.util.Bits) LongValues(org.apache.lucene.util.LongValues)

Example 10 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class Lucene54DocValuesProducer method getSorted.

@Override
public SortedDocValues getSorted(FieldInfo field) throws IOException {
    final int valueCount = (int) binaries.get(field.name).count;
    final LegacyBinaryDocValues binary = getLegacyBinary(field);
    NumericEntry entry = ords.get(field.name);
    final LongValues ordinals = getNumeric(entry);
    if (entry.format == SPARSE_COMPRESSED) {
        final SparseNumericDocValues sparseValues = ((SparseNumericDocValuesRandomAccessWrapper) ordinals).values;
        return new SortedDocValues() {

            @Override
            public int ordValue() {
                return (int) sparseValues.longValue();
            }

            @Override
            public BytesRef lookupOrd(int ord) {
                return binary.get(ord);
            }

            @Override
            public int getValueCount() {
                return valueCount;
            }

            @Override
            public int docID() {
                return sparseValues.docID();
            }

            @Override
            public int nextDoc() throws IOException {
                return sparseValues.nextDoc();
            }

            @Override
            public int advance(int target) throws IOException {
                return sparseValues.advance(target);
            }

            @Override
            public boolean advanceExact(int target) throws IOException {
                return sparseValues.advanceExact(target);
            }

            @Override
            public long cost() {
                return sparseValues.cost();
            }
        };
    }
    return new SortedDocValues() {

        private int docID = -1;

        private int ord;

        @Override
        public int docID() {
            return docID;
        }

        @Override
        public int nextDoc() throws IOException {
            assert docID != NO_MORE_DOCS;
            while (true) {
                docID++;
                if (docID == maxDoc) {
                    docID = NO_MORE_DOCS;
                    break;
                }
                ord = (int) ordinals.get(docID);
                if (ord != -1) {
                    break;
                }
            }
            return docID;
        }

        @Override
        public int advance(int target) throws IOException {
            if (target >= maxDoc) {
                docID = NO_MORE_DOCS;
                return docID;
            } else {
                docID = target - 1;
                return nextDoc();
            }
        }

        @Override
        public boolean advanceExact(int target) throws IOException {
            docID = target;
            ord = (int) ordinals.get(target);
            return ord != -1;
        }

        @Override
        public int ordValue() {
            return ord;
        }

        @Override
        public long cost() {
            // TODO
            return 0;
        }

        @Override
        public BytesRef lookupOrd(int ord) {
            return binary.get(ord);
        }

        @Override
        public int getValueCount() {
            return valueCount;
        }

        @Override
        public int lookupTerm(BytesRef key) throws IOException {
            if (binary instanceof CompressedBinaryDocValues) {
                return (int) ((CompressedBinaryDocValues) binary).lookupTerm(key);
            } else {
                return super.lookupTerm(key);
            }
        }

        @Override
        public TermsEnum termsEnum() throws IOException {
            if (binary instanceof CompressedBinaryDocValues) {
                return ((CompressedBinaryDocValues) binary).getTermsEnum();
            } else {
                return super.termsEnum();
            }
        }
    };
}
Also used : LongValues(org.apache.lucene.util.LongValues) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

LongValues (org.apache.lucene.util.LongValues)31 IOException (java.io.IOException)8 RandomAccessInput (org.apache.lucene.store.RandomAccessInput)8 IndexInput (org.apache.lucene.store.IndexInput)7 BytesRef (org.apache.lucene.util.BytesRef)6 IndexOutput (org.apache.lucene.store.IndexOutput)5 Directory (org.apache.lucene.store.Directory)4 ArrayList (java.util.ArrayList)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 NumericDocValues (org.apache.lucene.index.NumericDocValues)3 SortedDocValues (org.apache.lucene.index.SortedDocValues)3 Bits (org.apache.lucene.util.Bits)3 MultiDocValues (org.apache.lucene.index.MultiDocValues)2 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)2 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)2 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)2 DirectWriter (org.apache.lucene.util.packed.DirectWriter)2 FieldFacetStats (org.apache.solr.handler.component.FieldFacetStats)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1