Search in sources :

Example 1 with LeafBucketCollectorBase

use of org.elasticsearch.search.aggregations.LeafBucketCollectorBase in project elasticsearch by elastic.

the class ValueCountAggregator method getLeafCollector.

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            counts = bigArrays.grow(counts, bucket + 1);
            values.setDocument(doc);
            counts.increment(bucket, values.count());
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 2 with LeafBucketCollectorBase

use of org.elasticsearch.search.aggregations.LeafBucketCollectorBase in project elasticsearch by elastic.

the class ExtendedStatsAggregator method getLeafCollector.

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= counts.size()) {
                final long from = counts.size();
                final long overSize = BigArrays.overSize(bucket + 1);
                counts = bigArrays.resize(counts, overSize);
                sums = bigArrays.resize(sums, overSize);
                mins = bigArrays.resize(mins, overSize);
                maxes = bigArrays.resize(maxes, overSize);
                sumOfSqrs = bigArrays.resize(sumOfSqrs, overSize);
                mins.fill(from, overSize, Double.POSITIVE_INFINITY);
                maxes.fill(from, overSize, Double.NEGATIVE_INFINITY);
            }
            values.setDocument(doc);
            final int valuesCount = values.count();
            counts.increment(bucket, valuesCount);
            double sum = 0;
            double sumOfSqr = 0;
            double min = mins.get(bucket);
            double max = maxes.get(bucket);
            for (int i = 0; i < valuesCount; i++) {
                double value = values.valueAt(i);
                sum += value;
                sumOfSqr += value * value;
                min = Math.min(min, value);
                max = Math.max(max, value);
            }
            sums.increment(bucket, sum);
            sumOfSqrs.increment(bucket, sumOfSqr);
            mins.set(bucket, min);
            maxes.set(bucket, max);
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 3 with LeafBucketCollectorBase

use of org.elasticsearch.search.aggregations.LeafBucketCollectorBase in project elasticsearch by elastic.

the class SumAggregator method getLeafCollector.

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            sums = bigArrays.grow(sums, bucket + 1);
            values.setDocument(doc);
            final int valuesCount = values.count();
            double sum = 0;
            for (int i = 0; i < valuesCount; i++) {
                sum += values.valueAt(i);
            }
            sums.increment(bucket, sum);
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 4 with LeafBucketCollectorBase

use of org.elasticsearch.search.aggregations.LeafBucketCollectorBase in project elasticsearch by elastic.

the class GlobalOrdinalsStringTermsAggregator method newCollector.

protected LeafBucketCollector newCollector(final RandomAccessOrds ords, final LeafBucketCollector sub) {
    grow(ords.getValueCount());
    final SortedDocValues singleValues = DocValues.unwrapSingleton(ords);
    if (singleValues != null) {
        return new LeafBucketCollectorBase(sub, ords) {

            @Override
            public void collect(int doc, long bucket) throws IOException {
                assert bucket == 0;
                final int ord = singleValues.getOrd(doc);
                if (ord >= 0) {
                    collectExistingBucket(sub, doc, ord);
                }
            }
        };
    } else {
        return new LeafBucketCollectorBase(sub, ords) {

            @Override
            public void collect(int doc, long bucket) throws IOException {
                assert bucket == 0;
                ords.setDocument(doc);
                final int numOrds = ords.cardinality();
                for (int i = 0; i < numOrds; i++) {
                    final long globalOrd = ords.ordAt(i);
                    collectExistingBucket(sub, doc, globalOrd);
                }
            }
        };
    }
}
Also used : LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedDocValues(org.apache.lucene.index.SortedDocValues)

Example 5 with LeafBucketCollectorBase

use of org.elasticsearch.search.aggregations.LeafBucketCollectorBase in project elasticsearch by elastic.

the class LongTermsAggregator method getLeafCollector.

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    final SortedNumericDocValues values = getValues(valuesSource, ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long owningBucketOrdinal) throws IOException {
            assert owningBucketOrdinal == 0;
            values.setDocument(doc);
            final int valuesCount = values.count();
            long previous = Long.MAX_VALUE;
            for (int i = 0; i < valuesCount; ++i) {
                final long val = values.valueAt(i);
                if (previous != val || i == 0) {
                    if ((longFilter == null) || (longFilter.accept(val))) {
                        long bucketOrdinal = bucketOrds.add(val);
                        if (bucketOrdinal < 0) {
                            // already seen
                            bucketOrdinal = -1 - bucketOrdinal;
                            collectExistingBucket(sub, doc, bucketOrdinal);
                        } else {
                            collectBucket(sub, doc, bucketOrdinal);
                        }
                    }
                    previous = val;
                }
            }
        }
    };
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase)

Aggregations

LeafBucketCollectorBase (org.elasticsearch.search.aggregations.LeafBucketCollectorBase)23 BigArrays (org.elasticsearch.common.util.BigArrays)12 SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)10 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)3 NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)3 Scorer (org.apache.lucene.search.Scorer)2 BitSet (org.apache.lucene.util.BitSet)2 GeoPoint (org.elasticsearch.common.geo.GeoPoint)2 MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)2 SortedBinaryDocValues (org.elasticsearch.index.fielddata.SortedBinaryDocValues)2 LongIntHashMap (com.carrotsearch.hppc.LongIntHashMap)1 DoubleHistogram (org.HdrHistogram.DoubleHistogram)1 IndexReaderContext (org.apache.lucene.index.IndexReaderContext)1 SortedDocValues (org.apache.lucene.index.SortedDocValues)1 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Weight (org.apache.lucene.search.Weight)1 BytesRef (org.apache.lucene.util.BytesRef)1 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)1 LongObjectPagedHashMap (org.elasticsearch.common.util.LongObjectPagedHashMap)1