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));
}
}
};
}
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));
}
};
}
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);
}
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);
}
};
}
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();
}
};
}
Aggregations