summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/search
diff options
context:
space:
mode:
authorRyan Ernst <ryan@iernst.net>2017-06-02 13:41:26 -0700
committerGitHub <noreply@github.com>2017-06-02 13:41:26 -0700
commit0d8216d5afe66d1360ef06cab2c640180489d300 (patch)
tree13aa218f65b9b9657825f03149ad5a67666a5dc7 /core/src/test/java/org/elasticsearch/search
parenta926ace2e1e9c20dd93d94d129c616097e788e2f (diff)
Scripting: Convert CompiledTemplate to a ScriptContext (#25032)
This commit creates TemplateScript and associated classes so that templates no longer need a special ScriptService.compileTemplate method. The execute() method is equivalent to the old run() method. relates #20426
Diffstat (limited to 'core/src/test/java/org/elasticsearch/search')
-rw-r--r--core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java17
1 files changed, 4 insertions, 13 deletions
diff --git a/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java b/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java
index 50611a1cb9..89378a122a 100644
--- a/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java
+++ b/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java
@@ -33,6 +33,7 @@ import org.elasticsearch.plugins.ScriptPlugin;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptEngine;
+import org.elasticsearch.script.TemplateScript;
import org.elasticsearch.search.suggest.phrase.DirectCandidateGeneratorBuilder;
import org.elasticsearch.search.suggest.phrase.Laplace;
import org.elasticsearch.search.suggest.phrase.LinearInterpolation;
@@ -1025,26 +1026,16 @@ public class SuggestSearchIT extends ESIntegTestCase {
@Override
public <T> T compile(String scriptName, String scriptSource, ScriptContext<T> context, Map<String, String> params) {
- if (context.instanceClazz != ExecutableScript.class) {
+ if (context.instanceClazz != TemplateScript.class) {
throw new UnsupportedOperationException();
}
- ExecutableScript.Factory factory = p -> {
+ TemplateScript.Factory factory = p -> {
String script = scriptSource;
for (Entry<String, Object> entry : p.entrySet()) {
script = script.replace("{{" + entry.getKey() + "}}", String.valueOf(entry.getValue()));
}
String result = script;
- return new ExecutableScript() {
- @Override
- public void setNextVar(String name, Object value) {
- throw new UnsupportedOperationException("setNextVar not supported");
- }
-
- @Override
- public Object run() {
- return result;
- }
- };
+ return () -> result;
};
return context.factoryClazz.cast(factory);
}