use of org.opensearch.common.lucene.search.function.ScriptScoreQuery in project OpenSearch by opensearch-project.
the class ScriptScoreQueryTests method testExplainWithName.
public void testExplainWithName() throws IOException {
Script script = new Script("script using explain");
ScoreScript.LeafFactory factory = newFactory(script, true, explanation -> {
assertNotNull(explanation);
explanation.set("this explains the score");
return 1.0;
});
ScriptScoreQuery query = new ScriptScoreQuery(Queries.newMatchAllQuery(), "query1", script, factory, null, "index", 0, Version.CURRENT);
Weight weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
Explanation explanation = weight.explain(leafReaderContext, 0);
assertNotNull(explanation);
assertThat(explanation.getDescription(), equalTo("this explains the score"));
assertThat(explanation.getValue(), equalTo(1.0));
assertThat(explanation.getDetails(), arrayWithSize(1));
assertThat(explanation.getDetails()[0].getDescription(), equalTo("*:* (_name: query1)"));
}
Aggregations