Search in sources :

Example 6 with RandomAccessInput

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

the class Lucene54DocValuesProducer method getVariableBinary.

private LegacyBinaryDocValues getVariableBinary(FieldInfo field, final BinaryEntry bytes) throws IOException {
    final RandomAccessInput addressesData = this.data.randomAccessSlice(bytes.addressesOffset, bytes.addressesEndOffset - bytes.addressesOffset);
    final LongValues addresses = DirectMonotonicReader.getInstance(bytes.addressesMeta, addressesData);
    final IndexInput data = this.data.slice("var-binary", bytes.offset, bytes.addressesOffset - bytes.offset);
    final BytesRef term = new BytesRef(Math.max(0, bytes.maxLength));
    final byte[] buffer = term.bytes;
    return new LongBinaryDocValues() {

        @Override
        public BytesRef get(long id) {
            long startAddress = addresses.get(id);
            long endAddress = addresses.get(id + 1);
            int length = (int) (endAddress - startAddress);
            try {
                data.seek(startAddress);
                data.readBytes(buffer, 0, length);
                term.length = length;
                return term;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) LongValues(org.apache.lucene.util.LongValues) ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) IndexInput(org.apache.lucene.store.IndexInput) IOException(java.io.IOException) BytesRef(org.apache.lucene.util.BytesRef)

Example 7 with RandomAccessInput

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

the class Lucene70DocValuesProducer method getSortedNumeric.

@Override
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException {
    SortedNumericEntry entry = sortedNumerics.get(field.name);
    if (entry.numValues == entry.numDocsWithField) {
        return DocValues.singleton(getNumeric(entry));
    }
    final RandomAccessInput addressesInput = data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
    final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
    final LongValues values = getNumericValues(entry);
    if (entry.docsWithFieldOffset == -1) {
        // dense
        return new SortedNumericDocValues() {

            int doc = -1;

            long start, end;

            int count;

            @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);
                count = (int) (end - start);
                return doc = target;
            }

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

            @Override
            public long nextValue() throws IOException {
                return values.get(start++);
            }

            @Override
            public int docValueCount() {
                return count;
            }
        };
    } else {
        // sparse
        final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
        return new SortedNumericDocValues() {

            boolean set;

            long start, end;

            int count;

            @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 nextValue() throws IOException {
                set();
                return values.get(start++);
            }

            @Override
            public int docValueCount() {
                set();
                return count;
            }

            private void set() {
                if (set == false) {
                    final int index = disi.index();
                    start = addresses.get(index);
                    end = addresses.get(index + 1L);
                    count = (int) (end - start);
                    set = true;
                }
            }
        };
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) LongValues(org.apache.lucene.util.LongValues)

Example 8 with RandomAccessInput

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

the class Lucene70DocValuesProducer method getBinary.

@Override
public BinaryDocValues getBinary(FieldInfo field) throws IOException {
    BinaryEntry entry = binaries.get(field.name);
    if (entry.docsWithFieldOffset == -2) {
        return DocValues.emptyBinary();
    }
    final IndexInput bytesSlice = data.slice("fixed-binary", entry.dataOffset, entry.dataLength);
    if (entry.docsWithFieldOffset == -1) {
        // dense
        if (entry.minLength == entry.maxLength) {
            // fixed length
            final int length = entry.maxLength;
            return new DenseBinaryDocValues(maxDoc) {

                final BytesRef bytes = new BytesRef(new byte[length], 0, length);

                @Override
                public BytesRef binaryValue() throws IOException {
                    bytesSlice.seek((long) doc * length);
                    bytesSlice.readBytes(bytes.bytes, 0, length);
                    return bytes;
                }
            };
        } else {
            // variable length
            final RandomAccessInput addressesData = this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
            final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
            return new DenseBinaryDocValues(maxDoc) {

                final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);

                @Override
                public BytesRef binaryValue() throws IOException {
                    long startOffset = addresses.get(doc);
                    bytes.length = (int) (addresses.get(doc + 1L) - startOffset);
                    bytesSlice.seek(startOffset);
                    bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
                    return bytes;
                }
            };
        }
    } else {
        // sparse
        final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
        if (entry.minLength == entry.maxLength) {
            // fixed length
            final int length = entry.maxLength;
            return new SparseBinaryDocValues(disi) {

                final BytesRef bytes = new BytesRef(new byte[length], 0, length);

                @Override
                public BytesRef binaryValue() throws IOException {
                    bytesSlice.seek((long) disi.index() * length);
                    bytesSlice.readBytes(bytes.bytes, 0, length);
                    return bytes;
                }
            };
        } else {
            // variable length
            final RandomAccessInput addressesData = this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
            final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
            return new SparseBinaryDocValues(disi) {

                final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);

                @Override
                public BytesRef binaryValue() throws IOException {
                    final int index = disi.index();
                    long startOffset = addresses.get(index);
                    bytes.length = (int) (addresses.get(index + 1L) - startOffset);
                    bytesSlice.seek(startOffset);
                    bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
                    return bytes;
                }
            };
        }
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) IndexInput(org.apache.lucene.store.IndexInput) LongValues(org.apache.lucene.util.LongValues) BytesRef(org.apache.lucene.util.BytesRef)

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