use of org.elasticsearch.script.AbstractDoubleSearchScript in project elasticsearch by elastic.
the class ScriptScoreFunctionTests method testScriptScoresReturnsNaN.
/**
* Tests https://github.com/elastic/elasticsearch/issues/2426
*/
public void testScriptScoresReturnsNaN() throws IOException {
// script that always returns NaN
ScoreFunction scoreFunction = new ScriptScoreFunction(new Script("Double.NaN"), new SearchScript() {
@Override
public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
return new AbstractDoubleSearchScript() {
@Override
public double runAsDouble() {
return Double.NaN;
}
@Override
public void setDocument(int doc) {
// do nothing: we are a fake with no lookup
}
};
}
@Override
public boolean needsScores() {
return false;
}
});
LeafScoreFunction leafScoreFunction = scoreFunction.getLeafScoreFunction(null);
GeneralScriptException expected = expectThrows(GeneralScriptException.class, () -> {
leafScoreFunction.score(randomInt(), randomFloat());
});
assertTrue(expected.getMessage().contains("returned NaN"));
}
Aggregations