Search in sources :

Example 21 with SortedNumericDoubleValues

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

the class AbstractTDigestPercentilesAggregator 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 {
            states = bigArrays.grow(states, bucket + 1);
            TDigestState state = states.get(bucket);
            if (state == null) {
                state = new TDigestState(compression);
                states.set(bucket, state);
            }
            values.setDocument(doc);
            final int valueCount = values.count();
            for (int i = 0; i < valueCount; i++) {
                state.add(values.valueAt(i));
            }
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 22 with SortedNumericDoubleValues

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

the class FieldValueFactorFunction method getLeafScoreFunction.

@Override
public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) {
    final SortedNumericDoubleValues values;
    if (indexFieldData == null) {
        values = FieldData.emptySortedNumericDoubles(ctx.reader().maxDoc());
    } else {
        values = this.indexFieldData.load(ctx).getDoubleValues();
    }
    return new LeafScoreFunction() {

        @Override
        public double score(int docId, float subQueryScore) {
            values.setDocument(docId);
            final int numValues = values.count();
            double value;
            if (numValues > 0) {
                value = values.valueAt(0);
            } else if (missing != null) {
                value = missing;
            } else {
                throw new ElasticsearchException("Missing value for field [" + field + "]");
            }
            double val = value * boostFactor;
            double result = modifier.apply(val);
            if (Double.isNaN(result) || Double.isInfinite(result)) {
                throw new ElasticsearchException("Result of field modification [" + modifier.toString() + "(" + val + ")] must be a number");
            }
            return result;
        }

        @Override
        public Explanation explainScore(int docId, Explanation subQueryScore) {
            String modifierStr = modifier != null ? modifier.toString() : "";
            String defaultStr = missing != null ? "?:" + missing : "";
            double score = score(docId, subQueryScore.getValue());
            return Explanation.match(CombineFunction.toFloat(score), String.format(Locale.ROOT, "field value function: %s(doc['%s'].value%s * factor=%s)", modifierStr, field, defaultStr, boostFactor));
        }
    };
}
Also used : Explanation(org.apache.lucene.search.Explanation) ElasticsearchException(org.elasticsearch.ElasticsearchException) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 23 with SortedNumericDoubleValues

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

the class HalfFloatFielddataTests method testMultiValued.

public void testMultiValued() throws IOException {
    Directory dir = newDirectory();
    IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
    Document doc = new Document();
    for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 3f, false, true, false)) {
        doc.add(f);
    }
    for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 2f, false, true, false)) {
        doc.add(f);
    }
    w.addDocument(doc);
    final DirectoryReader dirReader = DirectoryReader.open(w);
    LeafReader reader = getOnlyLeafReader(dirReader);
    SortedNumericDoubleValues values = new SortedNumericDVIndexFieldData.SortedNumericHalfFloatFieldData(reader, "half_float").getDoubleValues();
    assertNull(FieldData.unwrapSingleton(values));
    values.setDocument(0);
    assertEquals(2, values.count());
    assertEquals(2f, values.valueAt(0), 0f);
    assertEquals(3f, values.valueAt(1), 0f);
    IOUtils.close(dirReader, w, dir);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) LeafReader(org.apache.lucene.index.LeafReader) IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryReader(org.apache.lucene.index.DirectoryReader) Document(org.apache.lucene.document.Document) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 24 with SortedNumericDoubleValues

use of org.elasticsearch.index.fielddata.SortedNumericDoubleValues 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 25 with SortedNumericDoubleValues

use of org.elasticsearch.index.fielddata.SortedNumericDoubleValues 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

SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)27 NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)11 LeafBucketCollectorBase (org.elasticsearch.search.aggregations.LeafBucketCollectorBase)10 BigArrays (org.elasticsearch.common.util.BigArrays)8 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)4 Document (org.apache.lucene.document.Document)3 DirectoryReader (org.apache.lucene.index.DirectoryReader)3 IndexWriter (org.apache.lucene.index.IndexWriter)3 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)3 Directory (org.apache.lucene.store.Directory)3 BitSet (org.apache.lucene.util.BitSet)3 FixedBitSet (org.apache.lucene.util.FixedBitSet)3 AtomicNumericFieldData (org.elasticsearch.index.fielddata.AtomicNumericFieldData)3 IndexableField (org.apache.lucene.index.IndexableField)2 LeafReader (org.apache.lucene.index.LeafReader)2 DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)2 Scorer (org.apache.lucene.search.Scorer)2 SortField (org.apache.lucene.search.SortField)2 GeoPoint (org.elasticsearch.common.geo.GeoPoint)2