Search in sources :

Example 1 with ScorerAware

use of org.elasticsearch.common.lucene.ScorerAware in project elasticsearch by elastic.

the class ScriptTestCase method exec.

/** Compiles and returns the result of {@code script} with access to {@code vars} and compile-time parameters */
public Object exec(String script, Map<String, Object> vars, Map<String, String> compileParams, Scorer scorer, boolean picky) {
    // test for ambiguity errors before running the actual script if picky is true
    if (picky) {
        ScriptInterface scriptInterface = new ScriptInterface(GenericElasticsearchScript.class);
        CompilerSettings pickySettings = new CompilerSettings();
        pickySettings.setPicky(true);
        pickySettings.setRegexesEnabled(CompilerSettings.REGEX_ENABLED.get(scriptEngineSettings()));
        Walker.buildPainlessTree(scriptInterface, getTestName(), script, pickySettings, null);
    }
    // test actual script execution
    Object object = scriptEngine.compile(null, script, compileParams);
    CompiledScript compiled = new CompiledScript(ScriptType.INLINE, getTestName(), "painless", object);
    ExecutableScript executableScript = scriptEngine.executable(compiled, vars);
    if (scorer != null) {
        ((ScorerAware) executableScript).setScorer(scorer);
    }
    return executableScript.run();
}
Also used : CompiledScript(org.elasticsearch.script.CompiledScript) ScorerAware(org.elasticsearch.common.lucene.ScorerAware) ExecutableScript(org.elasticsearch.script.ExecutableScript)

Aggregations

ScorerAware (org.elasticsearch.common.lucene.ScorerAware)1 CompiledScript (org.elasticsearch.script.CompiledScript)1 ExecutableScript (org.elasticsearch.script.ExecutableScript)1