Example usage for org.apache.lucene.util.packed MonotonicBlockPackedReader MonotonicBlockPackedReader

List of usage examples for org.apache.lucene.util.packed MonotonicBlockPackedReader MonotonicBlockPackedReader

Introduction

In this page you can find the example usage for org.apache.lucene.util.packed MonotonicBlockPackedReader MonotonicBlockPackedReader.

Prototype

private MonotonicBlockPackedReader(IndexInput in, int packedIntsVersion, int blockSize, long valueCount,
            boolean direct) throws IOException 

Source Link

Usage

From source file:org.apache.blur.lucene.codec.DiskDocValuesProducer.java

License:Apache License

private BinaryDocValues getVariableBinary(FieldInfo field, final BinaryEntry bytes) throws IOException {
    final IndexInput data = this.data.clone();

    Tracer trace = Trace.trace("getSorted - BlockPackedReader - create");
    final MonotonicBlockPackedReader addresses;
    try {/*from  www .j a v a  2 s.c o  m*/
        data.seek(bytes.addressesOffset);
        addresses = new MonotonicBlockPackedReader(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count,
                true);
    } finally {
        trace.done();
    }
    return new LongBinaryDocValues() {
        @Override
        public void get(long id, BytesRef result) {
            long startAddress = bytes.offset + (id == 0 ? 0 : addresses.get(id - 1));
            long endAddress = bytes.offset + addresses.get(id);
            int length = (int) (endAddress - startAddress);
            try {
                data.seek(startAddress);
                // NOTE: we could have one buffer, but various consumers (e.g. FieldComparatorSource) 
                // assume "they" own the bytes after calling this!
                final byte[] buffer = new byte[length];
                data.readBytes(buffer, 0, buffer.length);
                result.bytes = buffer;
                result.offset = 0;
                result.length = length;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
}

From source file:org.apache.blur.lucene.codec.DiskDocValuesProducer.java

License:Apache License

@Override
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
    final long valueCount = binaries.get(field.number).count;
    // we keep the byte[]s and list of ords on disk, these could be large
    final LongBinaryDocValues binary = (LongBinaryDocValues) getBinary(field);
    final LongNumericDocValues ordinals = getNumeric(ords.get(field.number));

    Tracer trace = Trace.trace("getSortedSet - MonotonicBlockPackedReader - create");
    final MonotonicBlockPackedReader ordIndex;
    try {//from w  w w .  ja  v  a  2  s. c  om
        NumericEntry entry = ordIndexes.get(field.number);
        IndexInput data = this.data.clone();
        data.seek(entry.offset);
        ordIndex = new MonotonicBlockPackedReader(data, entry.packedIntsVersion, entry.blockSize, entry.count,
                true);
    } finally {
        trace.done();
    }

    return new SortedSetDocValues() {
        long offset;
        long endOffset;

        @Override
        public long nextOrd() {
            if (offset == endOffset) {
                return NO_MORE_ORDS;
            } else {
                long ord = ordinals.get(offset);
                offset++;
                return ord;
            }
        }

        @Override
        public void setDocument(int docID) {
            offset = (docID == 0 ? 0 : ordIndex.get(docID - 1));
            endOffset = ordIndex.get(docID);
        }

        @Override
        public void lookupOrd(long ord, BytesRef result) {
            binary.get(ord, result);
        }

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