Search in sources :

Example 11 with NumericDoubleValues

use of org.elasticsearch.index.fielddata.NumericDoubleValues in project elasticsearch by elastic.

the class MaxAggregator 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 allValues = valuesSource.doubleValues(ctx);
    final NumericDoubleValues values = MultiValueMode.MAX.select(allValues, Double.NEGATIVE_INFINITY);
    return new LeafBucketCollectorBase(sub, allValues) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= maxes.size()) {
                long from = maxes.size();
                maxes = bigArrays.grow(maxes, bucket + 1);
                maxes.fill(from, maxes.size(), Double.NEGATIVE_INFINITY);
            }
            final double value = values.get(doc);
            double max = maxes.get(bucket);
            max = Math.max(max, value);
            maxes.set(bucket, max);
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 12 with NumericDoubleValues

use of org.elasticsearch.index.fielddata.NumericDoubleValues in project elasticsearch by elastic.

the class MinAggregator 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 allValues = valuesSource.doubleValues(ctx);
    final NumericDoubleValues values = MultiValueMode.MIN.select(allValues, Double.POSITIVE_INFINITY);
    return new LeafBucketCollectorBase(sub, allValues) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= mins.size()) {
                long from = mins.size();
                mins = bigArrays.grow(mins, bucket + 1);
                mins.fill(from, mins.size(), Double.POSITIVE_INFINITY);
            }
            final double value = values.get(doc);
            double min = mins.get(bucket);
            min = Math.min(min, value);
            mins.set(bucket, min);
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 13 with NumericDoubleValues

use of org.elasticsearch.index.fielddata.NumericDoubleValues in project elasticsearch by elastic.

the class FieldDataValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) {
            return docValues.get(doc);
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Example 14 with NumericDoubleValues

use of org.elasticsearch.index.fielddata.NumericDoubleValues in project elasticsearch by elastic.

the class DoubleValuesComparatorSource method newComparator.

@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
    assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());
    final double dMissingValue = (Double) missingObject(missingValue, reversed);
    // the comparator doesn't check docsWithField since we replace missing values in select()
    return new FieldComparator.DoubleComparator(numHits, null, null) {

        @Override
        protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
            final SortedNumericDoubleValues values = getValues(context);
            final NumericDoubleValues selectedValues;
            if (nested == null) {
                selectedValues = sortMode.select(values, dMissingValue);
            } else {
                final BitSet rootDocs = nested.rootDocs(context);
                final DocIdSetIterator innerDocs = nested.innerDocs(context);
                selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
            }
            return selectedValues.getRawDoubleValues();
        }

        @Override
        public void setScorer(Scorer scorer) {
            DoubleValuesComparatorSource.this.setScorer(scorer);
        }
    };
}
Also used : BitSet(org.apache.lucene.util.BitSet) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Scorer(org.apache.lucene.search.Scorer) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 15 with NumericDoubleValues

use of org.elasticsearch.index.fielddata.NumericDoubleValues in project elasticsearch by elastic.

the class FloatValuesComparatorSource method newComparator.

@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
    assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());
    final float dMissingValue = (Float) missingObject(missingValue, reversed);
    // the comparator doesn't check docsWithField since we replace missing values in select()
    return new FieldComparator.FloatComparator(numHits, null, null) {

        @Override
        protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
            final SortedNumericDoubleValues values = indexFieldData.load(context).getDoubleValues();
            final NumericDoubleValues selectedValues;
            if (nested == null) {
                selectedValues = sortMode.select(values, dMissingValue);
            } else {
                final BitSet rootDocs = nested.rootDocs(context);
                final DocIdSetIterator innerDocs = nested.innerDocs(context);
                selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
            }
            return selectedValues.getRawFloatValues();
        }
    };
}
Also used : BitSet(org.apache.lucene.util.BitSet) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Aggregations

NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)16 SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)12 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)4 DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)3 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)3 BitSet (org.apache.lucene.util.BitSet)3 BigArrays (org.elasticsearch.common.util.BigArrays)3 AtomicNumericFieldData (org.elasticsearch.index.fielddata.AtomicNumericFieldData)3 LeafBucketCollectorBase (org.elasticsearch.search.aggregations.LeafBucketCollectorBase)3 Scorer (org.apache.lucene.search.Scorer)2 SortField (org.apache.lucene.search.SortField)2 FixedBitSet (org.apache.lucene.util.FixedBitSet)2 IndexFieldData (org.elasticsearch.index.fielddata.IndexFieldData)2 Nested (org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested)2 MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)2 MultiValueMode (org.elasticsearch.search.MultiValueMode)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 BinaryDocValues (org.apache.lucene.index.BinaryDocValues)1 BitSetIterator (org.apache.lucene.util.BitSetIterator)1