Search in sources :

Example 1 with RandomAccessInput

use of org.apache.lucene.store.RandomAccessInput 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 2 with RandomAccessInput

use of org.apache.lucene.store.RandomAccessInput 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 3 with RandomAccessInput

use of org.apache.lucene.store.RandomAccessInput 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 4 with RandomAccessInput

use of org.apache.lucene.store.RandomAccessInput 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 5 with RandomAccessInput

use of org.apache.lucene.store.RandomAccessInput in project lucene-solr by apache.

the class Lucene54DocValuesProducer method getSparseNumericDocValues.

private SparseNumericDocValues getSparseNumericDocValues(NumericEntry entry) throws IOException {
    final RandomAccessInput docIdsData = this.data.randomAccessSlice(entry.missingOffset, entry.offset - entry.missingOffset);
    final LongValues docIDs = DirectMonotonicReader.getInstance(entry.monotonicMeta, docIdsData);
    // cannot be sparse
    final LongValues values = getNumeric(entry.nonMissingValues);
    return new SparseNumericDocValues(Math.toIntExact(entry.numDocsWithValue), docIDs, values);
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) LongValues(org.apache.lucene.util.LongValues)

Aggregations

RandomAccessInput (org.apache.lucene.store.RandomAccessInput)8 LongValues (org.apache.lucene.util.LongValues)8 IOException (java.io.IOException)2 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)2 IndexInput (org.apache.lucene.store.IndexInput)2 BytesRef (org.apache.lucene.util.BytesRef)2 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)1 Bits (org.apache.lucene.util.Bits)1