Search in sources :

Example 1 with PagedBytesDataInput

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

the class Lucene54DocValuesConsumer method addReverseTermIndex.

// writes reverse term index: used for binary searching a term into a range of 64 blocks
// for every 64 blocks (1024 terms) we store a term, trimming any suffix unnecessary for comparison
// terms are written as a contiguous byte[], but never spanning 2^15 byte boundaries.
private void addReverseTermIndex(FieldInfo field, final Iterable<BytesRef> values, int maxLength) throws IOException {
    long count = 0;
    BytesRefBuilder priorTerm = new BytesRefBuilder();
    priorTerm.grow(maxLength);
    BytesRef indexTerm = new BytesRef();
    long startFP = data.getFilePointer();
    PagedBytes pagedBytes = new PagedBytes(15);
    MonotonicBlockPackedWriter addresses = new MonotonicBlockPackedWriter(data, MONOTONIC_BLOCK_SIZE);
    for (BytesRef b : values) {
        int termPosition = (int) (count & REVERSE_INTERVAL_MASK);
        if (termPosition == 0) {
            int len = StringHelper.sortKeyLength(priorTerm.get(), b);
            indexTerm.bytes = b.bytes;
            indexTerm.offset = b.offset;
            indexTerm.length = len;
            addresses.add(pagedBytes.copyUsingLengthPrefix(indexTerm));
        } else if (termPosition == REVERSE_INTERVAL_MASK) {
            priorTerm.copyBytes(b);
        }
        count++;
    }
    addresses.finish();
    long numBytes = pagedBytes.getPointer();
    pagedBytes.freeze(true);
    PagedBytesDataInput in = pagedBytes.getDataInput();
    meta.writeLong(startFP);
    data.writeVLong(numBytes);
    data.copyBytes(in, numBytes);
}
Also used : MonotonicBlockPackedWriter(org.apache.lucene.util.packed.MonotonicBlockPackedWriter) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) PagedBytes(org.apache.lucene.util.PagedBytes) PagedBytesDataInput(org.apache.lucene.util.PagedBytes.PagedBytesDataInput) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

BytesRef (org.apache.lucene.util.BytesRef)1 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)1 PagedBytes (org.apache.lucene.util.PagedBytes)1 PagedBytesDataInput (org.apache.lucene.util.PagedBytes.PagedBytesDataInput)1 MonotonicBlockPackedWriter (org.apache.lucene.util.packed.MonotonicBlockPackedWriter)1