• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CompiledScript类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.elasticsearch.script.CompiledScript的典型用法代码示例。如果您正苦于以下问题:Java CompiledScript类的具体用法?Java CompiledScript怎么用?Java CompiledScript使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CompiledScript类属于org.elasticsearch.script包,在下文中一共展示了CompiledScript类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testBasics

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testBasics() {
    String template = "GET _search {\"query\": " + "{\"boosting\": {"
        + "\"positive\": {\"match\": {\"body\": \"gift\"}},"
        + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}"
        + "}}, \"negative_boost\": {{boost_val}} } }}";
    Map<String, Object> params = Collections.singletonMap("boost_val", "0.2");

    Mustache mustache = (Mustache) engine.compile(null, template, Collections.emptyMap());
    CompiledScript compiledScript = new CompiledScript(INLINE, "my-name", "mustache", mustache);
    ExecutableScript result = engine.executable(compiledScript, params);
    assertEquals(
            "Mustache templating broken",
            "GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
                    + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}}}, \"negative_boost\": 0.2 } }}",
            ((BytesReference) result.run()).utf8ToString()
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:MustacheTests.java


示例2: ExpressionExecutableScript

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public ExpressionExecutableScript(CompiledScript compiledScript, Map<String, Object> vars) {
    this.compiledScript = compiledScript;
    Expression expression = (Expression)this.compiledScript.compiled();
    int functionValuesLength = expression.variables.length;

    if (vars.size() != functionValuesLength) {
        throw new GeneralScriptException("Error using " + compiledScript + ". " +
                "The number of variables in an executable expression script [" +
                functionValuesLength + "] must match the number of variables in the variable map" +
                " [" + vars.size() + "].");
    }

    functionValuesArray = new ReplaceableConstDoubleValues[functionValuesLength];
    functionValuesMap = new HashMap<>();

    for (int functionValuesIndex = 0; functionValuesIndex < functionValuesLength; ++functionValuesIndex) {
        String variableName = expression.variables[functionValuesIndex];
        functionValuesArray[functionValuesIndex] = new ReplaceableConstDoubleValues();
        functionValuesMap.put(variableName, functionValuesArray[functionValuesIndex]);
    }

    for (String varsName : vars.keySet()) {
        setNextVar(varsName, vars.get(varsName));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:ExpressionExecutableScript.java


示例3: testArrayInArrayAccess

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testArrayInArrayAccess() throws Exception {
    String template = "{{data.0.0}} {{data.0.1}}";
    CompiledScript mustache = new CompiledScript(INLINE, "inline", "mustache", engine.compile(null, template, Collections.emptyMap()));
    Map<String, Object> vars = new HashMap<>();
    Object data = randomFrom(
        new String[][] { new String[] { "foo", "bar" }},
        Collections.singletonList(new String[] { "foo", "bar" }),
        singleton(new String[] { "foo", "bar" })
    );
    vars.put("data", data);
    Object output = engine.executable(mustache, vars).run();
    assertThat(output, notNullValue());
    assertThat(output, instanceOf(BytesReference.class));
    BytesReference bytes = (BytesReference) output;
    assertThat(bytes.utf8ToString(), equalTo("foo bar"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MustacheTests.java


示例4: testSizeAccessForCollectionsAndArrays

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testSizeAccessForCollectionsAndArrays() throws Exception {
    String[] randomArrayValues = generateRandomStringArray(10, 20, false);
    List<String> randomList = Arrays.asList(generateRandomStringArray(10, 20, false));

    String template = "{{data.array.size}} {{data.list.size}}";
    CompiledScript mustache = new CompiledScript(INLINE, "inline", "mustache", engine.compile(null, template, Collections.emptyMap()));
    Map<String, Object> data = new HashMap<>();
    data.put("array", randomArrayValues);
    data.put("list", randomList);
    Map<String, Object> vars = new HashMap<>();
    vars.put("data", data);

    Object output = engine.executable(mustache, vars).run();
    assertThat(output, notNullValue());
    assertThat(output, instanceOf(BytesReference.class));

    BytesReference bytes = (BytesReference) output;
    String expectedString = String.format(Locale.ROOT, "%s %s", randomArrayValues.length, randomList.size());
    assertThat(bytes.utf8ToString(), equalTo(expectedString));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:MustacheTests.java


示例5: search

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
/**
 * Retrieve a {@link SearchScript} for later use.
 * @param compiledScript A previously compiled script.
 * @param lookup The object that ultimately allows access to search fields.
 * @param vars The variables to be used in the script.
 * @return An {@link SearchScript} with the currently specified variables.
 */
@Override
public SearchScript search(final CompiledScript compiledScript, final SearchLookup lookup, final Map<String, Object> vars) {
    return new SearchScript() {
        /**
         * Get the search script that will have access to search field values.
         * @param context The LeafReaderContext to be used.
         * @return A script that will have the search fields from the current context available for use.
         */
        @Override
        public LeafSearchScript getLeafSearchScript(final LeafReaderContext context) throws IOException {
            return new ScriptImpl((GenericElasticsearchScript) compiledScript.compiled(), vars, lookup.getLeafSearchLookup(context));
        }

        /**
         * Whether or not the score is needed.
         */
        @Override
        public boolean needsScores() {
            return ((GenericElasticsearchScript) compiledScript.compiled()).uses$_score();
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:PainlessScriptEngineService.java


示例6: exec

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
/** 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();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:ScriptTestCase.java


示例7: testChangingVarsCrossExecution1

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testChangingVarsCrossExecution1() {
    Map<String, Object> vars = new HashMap<>();
    Map<String, Object> ctx = new HashMap<>();
    vars.put("ctx", ctx);

    Object compiledScript = scriptEngine.compile(null,
            "return ctx.value;", Collections.emptyMap());
    ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptType.INLINE,
            "testChangingVarsCrossExecution1", "painless", compiledScript), vars);

    ctx.put("value", 1);
    Object o = script.run();
    assertEquals(1, ((Number) o).intValue());

    ctx.put("value", 2);
    o = script.run();
    assertEquals(2, ((Number) o).intValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ScriptEngineTests.java


示例8: executable

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
@Override
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> params) {
    final String field = (String) compiledScript.compiled();
    return new ExecutableScript() {

        Map<String, Object> vars = new HashMap<>();

        @Override
        public void setNextVar(String name, Object value) {
            vars.put(name, value);
        }

        @Override
        public Object run() {
            Map<String, Object> ctx = (Map<String, Object>) vars.get("ctx");
            assertNotNull(ctx);
            Map<String, Object> source = (Map<String, Object>) ctx.get("_source");
            Number currentValue = (Number) source.get(field);
            Number inc = params == null ? 1L : (Number) params.getOrDefault("inc", 1);
            source.put(field, currentValue.longValue() + inc.longValue());
            return ctx;
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:UpdateIT.java


示例9: executable

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
@Override
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> params) {
    String script = (String) compiledScript.compiled();
    for (Entry<String, Object> entry : params.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 new BytesArray(result);
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:SuggestSearchIT.java


示例10: init

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
@BeforeClass
public static void init() throws IOException {
    Path genericConfigFolder = createTempDir();
    Settings baseSettings = Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
            .put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder)
            .build();
    Environment environment = new Environment(baseSettings);
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngineService()));
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    scriptService = new ScriptService(baseSettings, environment,
            new ResourceWatcherService(baseSettings, null), scriptEngineRegistry, scriptContextRegistry, scriptSettings) {
        @Override
        public CompiledScript compile(Script script, ScriptContext scriptContext) {
            return new CompiledScript(ScriptType.INLINE, "mockName", "test", script);
        }
    };

    SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:AbstractSortTestCase.java


示例11: search

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
@Override
public SearchScript search(CompiledScript compiledScript, final SearchLookup lookup, @Nullable final Map<String, Object> vars) {
    final VectorScoreScript.Factory scriptFactory = (VectorScoreScript.Factory) compiledScript.compiled();
    final VectorScoreScript script = (VectorScoreScript) scriptFactory.newScript(vars);
    return new SearchScript() {
        @Override
        public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
            script.setBinaryEmbeddingReader(context.reader().getBinaryDocValues(script.field));
            return script;
        }
        @Override
        public boolean needsScores() {
            return scriptFactory.needsScores();
        }
    };
}
 
开发者ID:lior-k,项目名称:fast-elasticsearch-vector-scoring,代码行数:17,代码来源:VectorScoringScriptEngineService.java


示例12: search

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
@Override
public SearchScript search(final CompiledScript compiledScript, final SearchLookup lookup, @Nullable final Map<String, Object> vars) {
    return new SearchScript() {

        @Override
        public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
            final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
            boolean debug = true;
            if (vars != null && vars.containsKey("debug")) {
                debug = (Boolean)vars.get("debug");
            }
            return ((Factory) compiledScript.compiled()).newScript(leafLookup, debug);
        }

        @Override
        public boolean needsScores() {
            // TODO: can we reliably know if a vectorizer script does not make use of _score
            return false;
        }
    };
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:23,代码来源:PMMLModelScriptEngineService.java


示例13: provideUserScript

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
@Provides
@Singleton
public UserScript provideUserScript(ArangoDbConfig config, ScriptService scriptService) {
	String scriptString = config.getArangodbScript();
	if (isBlank(scriptString)) {
		return new NullUserScript();
	}

	String scriptType = config.getArangodbScripttype();
	if (isBlank(scriptType)) {
		return new NullUserScript();
	}

	CompiledScript compiled = scriptService.compile(scriptType, scriptString, ScriptType.INLINE);
	return new ConcreteUserScript(scriptService, compiled);
}
 
开发者ID:arangodb,项目名称:elasticsearch-river-arangodb,代码行数:17,代码来源:ArangoDbRiverModule.java


示例14: ExpressionSearchScript

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
ExpressionSearchScript(CompiledScript c, SimpleBindings b, ReplaceableConstDoubleValueSource v, boolean needsScores) {
    compiledScript = c;
    bindings = b;
    source = ((Expression)compiledScript.compiled()).getDoubleValuesSource(bindings);
    specialValue = v;
    this.needsScores = needsScores;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:ExpressionSearchScript.java


示例15: testSimple

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testSimple() throws IOException {
    String templateString =
              "{" 
            + "\"inline\":{\"match_{{template}}\": {}},"
            + "\"params\":{\"template\":\"all\"}"
            + "}";
    XContentParser parser = createParser(JsonXContent.jsonXContent, templateString);
    Script script = Script.parse(parser);
    CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, null, "mustache",
            qe.compile(null, script.getIdOrCode(), Collections.emptyMap()));
    ExecutableScript executableScript = qe.executable(compiledScript, script.getParams());
    assertThat(((BytesReference) executableScript.run()).utf8ToString(), equalTo("{\"match_all\":{}}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:MustacheScriptEngineTests.java


示例16: testParseTemplateAsSingleStringWithConditionalClause

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testParseTemplateAsSingleStringWithConditionalClause() throws IOException {
    String templateString =
              "{"
            + "  \"inline\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + "  \"params\":{"
            + "    \"template\":\"all\","
            + "    \"use_it\": true"
            + "  }"
            + "}";
    XContentParser parser = createParser(JsonXContent.jsonXContent, templateString);
    Script script = Script.parse(parser);
    CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, null, "mustache",
            qe.compile(null, script.getIdOrCode(), Collections.emptyMap()));
    ExecutableScript executableScript = qe.executable(compiledScript, script.getParams());
    assertThat(((BytesReference) executableScript.run()).utf8ToString(), equalTo("{ \"match_all\":{} }"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:MustacheScriptEngineTests.java


示例17: testJsonEscapeEncoder

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testJsonEscapeEncoder() {
    final ScriptEngineService engine = new MustacheScriptEngineService();
    final Map<String, String> params = randomBoolean() ? singletonMap(Script.CONTENT_TYPE_OPTION, JSON_MIME_TYPE) : emptyMap();

    Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
    CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);

    ExecutableScript executable = engine.executable(compiled, singletonMap("value", "a \"value\""));
    BytesReference result = (BytesReference) executable.run();
    assertThat(result.utf8ToString(), equalTo("{\"field\": \"a \\\"value\\\"\"}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CustomMustacheFactoryTests.java


示例18: testDefaultEncoder

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testDefaultEncoder() {
    final ScriptEngineService engine = new MustacheScriptEngineService();
    final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, PLAIN_TEXT_MIME_TYPE);

    Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
    CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);

    ExecutableScript executable = engine.executable(compiled, singletonMap("value", "a \"value\""));
    BytesReference result = (BytesReference) executable.run();
    assertThat(result.utf8ToString(), equalTo("{\"field\": \"a \"value\"\"}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CustomMustacheFactoryTests.java


示例19: testUrlEncoder

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
public void testUrlEncoder() {
    final ScriptEngineService engine = new MustacheScriptEngineService();
    final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, X_WWW_FORM_URLENCODED_MIME_TYPE);

    Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
    CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);

    ExecutableScript executable = engine.executable(compiled, singletonMap("value", "tilde~ AND date:[2016 FROM*]"));
    BytesReference result = (BytesReference) executable.run();
    assertThat(result.utf8ToString(), equalTo("{\"field\": \"tilde%7E+AND+date%3A%5B2016+FROM*%5D\"}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CustomMustacheFactoryTests.java


示例20: applyScript

import org.elasticsearch.script.CompiledScript; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T extends ActionRequest> T applyScript(Consumer<Map<String, Object>> scriptBody) {
    IndexRequest index = new IndexRequest("index", "type", "1").source(singletonMap("foo", "bar"));
    ScrollableHitSource.Hit doc = new ScrollableHitSource.BasicHit("test", "type", "id", 0);
    ExecutableScript executableScript = new SimpleExecutableScript(scriptBody);

    when(scriptService.executable(any(CompiledScript.class), Matchers.<Map<String, Object>>any()))
            .thenReturn(executableScript);
    AbstractAsyncBulkByScrollAction<Request> action = action(scriptService, request().setScript(EMPTY_SCRIPT));
    RequestWrapper<?> result = action.buildScriptApplier().apply(AbstractAsyncBulkByScrollAction.wrap(index), doc);
    return (result != null) ? (T) result.self() : null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:AbstractAsyncBulkByScrollActionScriptTestCase.java



注:本文中的org.elasticsearch.script.CompiledScript类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TestUserGroupInformation类代码示例发布时间:2022-05-22
下一篇:
Java Rational类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap