Example usage for org.apache.lucene.util.packed PackedLongValues packedBuilder

List of usage examples for org.apache.lucene.util.packed PackedLongValues packedBuilder

Introduction

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

Prototype

public static PackedLongValues.Builder packedBuilder(float acceptableOverheadRatio) 

Source Link

Usage

From source file:org.codelibs.elasticsearch.search.aggregations.bucket.BestBucketsDeferringCollector.java

License:Apache License

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx) throws IOException {
    finishLeaf();/* ww w . j av  a 2 s.  c o  m*/

    context = ctx;
    docDeltas = PackedLongValues.packedBuilder(PackedInts.DEFAULT);
    buckets = PackedLongValues.packedBuilder(PackedInts.DEFAULT);

    return new LeafBucketCollector() {
        int lastDoc = 0;

        @Override
        public void collect(int doc, long bucket) throws IOException {
            docDeltas.add(doc - lastDoc);
            buckets.add(bucket);
            lastDoc = doc;
            maxBucket = Math.max(maxBucket, bucket);
        }
    };
}

From source file:org.elasticsearch.search.aggregations.bucket.MergingBucketsDeferringCollector.java

License:Apache License

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx) throws IOException {
    finishLeaf();// w  ww  .  j  a  va2s  .c  o  m

    context = ctx;
    docDeltas = PackedLongValues.packedBuilder(PackedInts.DEFAULT);
    buckets = PackedLongValues.packedBuilder(PackedInts.DEFAULT);

    return new LeafBucketCollector() {
        int lastDoc = 0;

        @Override
        public void collect(int doc, long bucket) {
            docDeltas.add(doc - lastDoc);
            buckets.add(bucket);
            lastDoc = doc;
            maxBucket = Math.max(maxBucket, bucket);
        }
    };
}

From source file:org.elasticsearch.search.aggregations.bucket.MergingBucketsDeferringCollector.java

License:Apache License

public void mergeBuckets(long[] mergeMap) {

    List<Entry> newEntries = new ArrayList<>(entries.size());
    for (Entry sourceEntry : entries) {
        PackedLongValues.Builder newBuckets = PackedLongValues.packedBuilder(PackedInts.DEFAULT);
        for (PackedLongValues.Iterator itr = sourceEntry.buckets.iterator(); itr.hasNext();) {
            long bucket = itr.next();
            newBuckets.add(mergeMap[Math.toIntExact(bucket)]);
        }/*from   ww  w  .ja v a2 s. c o  m*/
        newEntries.add(new Entry(sourceEntry.context, sourceEntry.docDeltas, newBuckets.build()));
    }
    entries = newEntries;

    // if there are buckets that have been collected in the current segment
    // we need to update the bucket ordinals there too
    if (buckets.size() > 0) {
        PackedLongValues currentBuckets = buckets.build();
        PackedLongValues.Builder newBuckets = PackedLongValues.packedBuilder(PackedInts.DEFAULT);
        for (PackedLongValues.Iterator itr = currentBuckets.iterator(); itr.hasNext();) {
            long bucket = itr.next();
            newBuckets.add(mergeMap[Math.toIntExact(bucket)]);
        }
        buckets = newBuckets;
    }
}