use of org.elasticsearch.index.fielddata.AtomicFieldData in project elasticsearch by elastic.
the class DocValueFieldsFetchSubPhase method hitExecute.
@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
if (context.collapse() != null) {
// retrieve the `doc_value` associated with the collapse field
String name = context.collapse().getFieldType().name();
if (context.docValueFieldsContext() == null) {
context.docValueFieldsContext(new DocValueFieldsContext(Collections.singletonList(name)));
} else if (context.docValueFieldsContext().fields().contains(name) == false) {
context.docValueFieldsContext().fields().add(name);
}
}
if (context.docValueFieldsContext() == null) {
return;
}
for (String field : context.docValueFieldsContext().fields()) {
if (hitContext.hit().fieldsOrNull() == null) {
hitContext.hit().fields(new HashMap<>(2));
}
SearchHitField hitField = hitContext.hit().getFields().get(field);
if (hitField == null) {
hitField = new SearchHitField(field, new ArrayList<>(2));
hitContext.hit().getFields().put(field, hitField);
}
MappedFieldType fieldType = context.mapperService().fullName(field);
if (fieldType != null) {
/* Because this is called once per document we end up creating a new ScriptDocValues for every document which is important
* because the values inside ScriptDocValues might be reused for different documents (Dates do this). */
AtomicFieldData data = context.fieldData().getForField(fieldType).load(hitContext.readerContext());
ScriptDocValues<?> values = data.getScriptValues();
values.setNextDocId(hitContext.docId());
hitField.getValues().addAll(values);
}
}
}
use of org.elasticsearch.index.fielddata.AtomicFieldData in project elasticsearch by elastic.
the class RandomScoreFunction method getLeafScoreFunction.
@Override
public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) {
AtomicFieldData leafData = uidFieldData.load(ctx);
final SortedBinaryDocValues uidByteData = leafData.getBytesValues();
if (uidByteData == null)
throw new NullPointerException("failed to get uid byte data");
return new LeafScoreFunction() {
@Override
public double score(int docId, float subQueryScore) {
uidByteData.setDocument(docId);
int hash = StringHelper.murmurhash3_x86_32(uidByteData.valueAt(0), saltedSeed);
// only use the lower 24 bits to construct a float from 0.0-1.0
return (hash & 0x00FFFFFF) / (float) (1 << 24);
}
@Override
public Explanation explainScore(int docId, Explanation subQueryScore) {
return Explanation.match(CombineFunction.toFloat(score(docId, subQueryScore.getValue())), "random score function (seed: " + originalSeed + ")");
}
};
}
Aggregations