Search in sources :

Example 1 with AbstractDoubleSearchScript

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"));
}
Also used : Script(org.elasticsearch.script.Script) AbstractDoubleSearchScript(org.elasticsearch.script.AbstractDoubleSearchScript) LeafSearchScript(org.elasticsearch.script.LeafSearchScript) SearchScript(org.elasticsearch.script.SearchScript) AbstractDoubleSearchScript(org.elasticsearch.script.AbstractDoubleSearchScript) LeafSearchScript(org.elasticsearch.script.LeafSearchScript) SearchScript(org.elasticsearch.script.SearchScript) LeafSearchScript(org.elasticsearch.script.LeafSearchScript) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) AbstractDoubleSearchScript(org.elasticsearch.script.AbstractDoubleSearchScript) GeneralScriptException(org.elasticsearch.script.GeneralScriptException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 AbstractDoubleSearchScript (org.elasticsearch.script.AbstractDoubleSearchScript)1 GeneralScriptException (org.elasticsearch.script.GeneralScriptException)1 LeafSearchScript (org.elasticsearch.script.LeafSearchScript)1 Script (org.elasticsearch.script.Script)1 SearchScript (org.elasticsearch.script.SearchScript)1