Example usage for org.apache.lucene.util.packed MonotonicBlockPackedWriter add

List of usage examples for org.apache.lucene.util.packed MonotonicBlockPackedWriter add

Introduction

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

Prototype

@Override
    public void add(long l) throws IOException 

Source Link

Usage

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

License:Apache License

@Override
public void addBinaryField(FieldInfo field, final Iterable<BytesRef> values) throws IOException {
    // write the byte[] data
    meta.writeVInt(field.number);//from ww w .  ja v  a2 s . c  o  m
    meta.writeByte(DiskDocValuesFormat.BINARY);
    int minLength = Integer.MAX_VALUE;
    int maxLength = Integer.MIN_VALUE;
    final long startFP = data.getFilePointer();
    long count = 0;
    for (BytesRef v : values) {
        minLength = Math.min(minLength, v.length);
        maxLength = Math.max(maxLength, v.length);
        data.writeBytes(v.bytes, v.offset, v.length);
        count++;
    }
    meta.writeVInt(minLength);
    meta.writeVInt(maxLength);
    meta.writeVLong(count);
    meta.writeLong(startFP);

    // if minLength == maxLength, its a fixed-length byte[], we are done (the addresses are implicit)
    // otherwise, we need to record the length fields...
    if (minLength != maxLength) {
        meta.writeLong(data.getFilePointer());
        meta.writeVInt(PackedInts.VERSION_CURRENT);
        meta.writeVInt(BLOCK_SIZE);

        final MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(data, BLOCK_SIZE);
        long addr = 0;
        for (BytesRef v : values) {
            addr += v.length;
            writer.add(addr);
        }
        writer.finish();
    }
}

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

License:Apache License

@Override
public void addSortedSetField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrdCount,
        Iterable<Number> ords) throws IOException {
    meta.writeVInt(field.number);/*  w  ww .  j  a v  a 2s.c  o  m*/
    meta.writeByte(DiskDocValuesFormat.SORTED_SET);
    // write the ord -> byte[] as a binary field
    addBinaryField(field, values);
    // write the stream of ords as a numeric field
    // NOTE: we could return an iterator that delta-encodes these within a doc
    addNumericField(field, ords);

    // write the doc -> ord count as a absolute index to the stream
    meta.writeVInt(field.number);
    meta.writeByte(DiskDocValuesFormat.NUMERIC);
    meta.writeVInt(PackedInts.VERSION_CURRENT);
    meta.writeLong(data.getFilePointer());
    meta.writeVLong(maxDoc);
    meta.writeVInt(BLOCK_SIZE);

    final MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(data, BLOCK_SIZE);
    long addr = 0;
    for (Number v : docToOrdCount) {
        addr += v.longValue();
        writer.add(addr);
    }
    writer.finish();
}