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

Java SearchScript类代码示例

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

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



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

示例1: search

import org.elasticsearch.script.SearchScript; //导入依赖的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


示例2: createInternal

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
@Override
public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators,
        Map<String, Object> metaData) throws IOException {
    if (collectsFromSingleBucket == false) {
        return asMultiBucketAggregator(this, context, parent);
    }
    Map<String, Object> params = this.params;
    if (params != null) {
        params = deepCopyParams(params, context);
    } else {
        params = new HashMap<>();
        params.put("_agg", new HashMap<String, Object>());
    }

    final ExecutableScript initScript = this.initScript.apply(params);
    final SearchScript mapScript = this.mapScript.apply(params);
    final ExecutableScript combineScript = this.combineScript.apply(params);

    final Script reduceScript = deepCopyScript(this.reduceScript, context);
    if (initScript != null) {
        initScript.run();
    }
    return new ScriptedMetricAggregator(name, mapScript,
            combineScript, reduceScript, params, context, parent,
            pipelineAggregators, metaData);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ScriptedMetricAggregatorFactory.java


示例3: doBuild

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
@Override
protected ScriptedMetricAggregatorFactory doBuild(SearchContext context, AggregatorFactory<?> parent,
        Builder subfactoriesBuilder) throws IOException {

    QueryShardContext queryShardContext = context.getQueryShardContext();
    Function<Map<String, Object>, ExecutableScript> executableInitScript;
    if (initScript != null) {
        executableInitScript = queryShardContext.getLazyExecutableScript(initScript, ScriptContext.Standard.AGGS);
    } else {
        executableInitScript = (p) -> null;
    }
    Function<Map<String, Object>, SearchScript> searchMapScript = queryShardContext.getLazySearchScript(mapScript,
        ScriptContext.Standard.AGGS);
    Function<Map<String, Object>, ExecutableScript> executableCombineScript;
    if (combineScript != null) {
        executableCombineScript = queryShardContext.getLazyExecutableScript(combineScript, ScriptContext.Standard.AGGS);
    } else {
        executableCombineScript = (p) -> null;
    }
    return new ScriptedMetricAggregatorFactory(name, searchMapScript, executableInitScript, executableCombineScript, reduceScript,
            params, context, parent, subfactoriesBuilder, metaData);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:ScriptedMetricAggregationBuilder.java


示例4: doBuild

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
@Override
protected TopHitsAggregatorFactory doBuild(SearchContext context, AggregatorFactory<?> parent, Builder subfactoriesBuilder)
        throws IOException {
    List<ScriptFieldsContext.ScriptField> fields = new ArrayList<>();
    if (scriptFields != null) {
        for (ScriptField field : scriptFields) {
            SearchScript searchScript = context.getQueryShardContext().getSearchScript(field.script(),
                ScriptContext.Standard.SEARCH);
            fields.add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
                field.fieldName(), searchScript, field.ignoreFailure()));
        }
    }

    final Optional<SortAndFormats> optionalSort;
    if (sorts == null) {
        optionalSort = Optional.empty();
    } else {
        optionalSort = SortBuilder.buildSort(sorts, context.getQueryShardContext());
    }
    return new TopHitsAggregatorFactory(name, from, size, explain, version, trackScores, optionalSort, highlightBuilder,
            storedFieldsContext, fieldDataFields, fields, fetchSourceContext, context, parent, subfactoriesBuilder, metaData);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TopHitsAggregationBuilder.java


示例5: search

import org.elasticsearch.script.SearchScript; //导入依赖的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


示例6: search

import org.elasticsearch.script.SearchScript; //导入依赖的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


示例7: testNeedsScores

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
public void testNeedsScores() {
    IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double");

    PainlessScriptEngineService service = new PainlessScriptEngineService(Settings.EMPTY);
    SearchLookup lookup = new SearchLookup(index.mapperService(), index.fieldData(), null);

    Object compiled = service.compile(null, "1.2", Collections.emptyMap());
    SearchScript ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled),
                                     lookup, Collections.<String, Object>emptyMap());
    assertFalse(ss.needsScores());

    compiled = service.compile(null, "doc['d'].value", Collections.emptyMap());
    ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled),
                        lookup, Collections.<String, Object>emptyMap());
    assertFalse(ss.needsScores());

    compiled = service.compile(null, "1/_score", Collections.emptyMap());
    ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled),
                        lookup, Collections.<String, Object>emptyMap());
    assertTrue(ss.needsScores());

    compiled = service.compile(null, "doc['d'].value * _score", Collections.emptyMap());
    ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled),
                        lookup, Collections.<String, Object>emptyMap());
    assertTrue(ss.needsScores());
    service.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:NeedsScoreTests.java


示例8: ScriptedMetricAggregator

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
protected ScriptedMetricAggregator(String name, SearchScript mapScript, ExecutableScript combineScript,
                                   Script reduceScript,
        Map<String, Object> params, SearchContext context, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
        throws IOException {
    super(name, context, parent, pipelineAggregators, metaData);
    this.params = params;
    this.mapScript = mapScript;
    this.combineScript = combineScript;
    this.reduceScript = reduceScript;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ScriptedMetricAggregator.java


示例9: ScriptedMetricAggregatorFactory

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
public ScriptedMetricAggregatorFactory(String name, Function<Map<String, Object>, SearchScript> mapScript,
        Function<Map<String, Object>, ExecutableScript> initScript, Function<Map<String, Object>, ExecutableScript> combineScript,
        Script reduceScript, Map<String, Object> params, SearchContext context, AggregatorFactory<?> parent,
        AggregatorFactories.Builder subFactories, Map<String, Object> metaData) throws IOException {
    super(name, context, parent, subFactories, metaData);
    this.mapScript = mapScript;
    this.initScript = initScript;
    this.combineScript = combineScript;
    this.reduceScript = reduceScript;
    this.params = params;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:ScriptedMetricAggregatorFactory.java


示例10: createScript

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
private static SearchScript createScript(Script script, QueryShardContext context) {
    if (script == null) {
        return null;
    } else {
        return context.getSearchScript(script, ScriptContext.Standard.AGGS);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:ValuesSourceConfig.java


示例11: doToFunction

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
    try {
        SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);
        return new ScriptScoreFunction(script, searchScript);
    } catch (Exception e) {
        throw new QueryShardException(context, "script_score: the script could not be loaded", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ScriptScoreFunctionBuilder.java


示例12: setupInnerHitsContext

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
private void setupInnerHitsContext(QueryShardContext context, InnerHitsContext.BaseInnerHits innerHitsContext) throws IOException {
    innerHitsContext.from(from);
    innerHitsContext.size(size);
    innerHitsContext.explain(explain);
    innerHitsContext.version(version);
    innerHitsContext.trackScores(trackScores);
    if (storedFieldsContext != null) {
        innerHitsContext.storedFieldsContext(storedFieldsContext);
    }
    if (docValueFields != null) {
        innerHitsContext.docValueFieldsContext(new DocValueFieldsContext(docValueFields));
    }
    if (scriptFields != null) {
        for (ScriptField field : scriptFields) {
            SearchScript searchScript = innerHitsContext.getQueryShardContext().getSearchScript(field.script(),
                ScriptContext.Standard.SEARCH);
            innerHitsContext.scriptFields().add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
                    field.fieldName(), searchScript, field.ignoreFailure()));
        }
    }
    if (fetchSourceContext != null) {
        innerHitsContext.fetchSourceContext(fetchSourceContext);
    }
    if (sorts != null) {
        Optional<SortAndFormats> optionalSort = SortBuilder.buildSort(sorts, context);
        if (optionalSort.isPresent()) {
            innerHitsContext.sort(optionalSort.get());
        }
    }
    if (highlightBuilder != null) {
        innerHitsContext.highlight(highlightBuilder.build(context));
    }
    ParsedQuery parsedQuery = new ParsedQuery(query.toQuery(context), context.copyNamedQueries());
    innerHitsContext.parsedQuery(parsedQuery);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:InnerHitBuilder.java


示例13: testScriptScoresReturnsNaN

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


示例14: compile

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
private SearchScript compile(String expression) {
    Object compiled = service.compile(null, expression, Collections.emptyMap());
    return service.search(new CompiledScript(ScriptType.INLINE, "randomName", "expression", compiled), lookup, Collections.<String, Object>emptyMap());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ExpressionTests.java


示例15: search

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
@Override
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup,
        @Nullable Map<String, Object> vars) {
    throw new UnsupportedOperationException();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:MustacheScriptEngineService.java


示例16: script

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
public SearchScript script() {
    return script;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ValuesSourceConfig.java


示例17: Script

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
public Script(SearchScript script) {
    this.script = script;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ValuesSource.java


示例18: WithScript

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
public WithScript(Numeric delegate, SearchScript script) {
    this.delegate = delegate;
    this.script = script;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ValuesSource.java


示例19: ScriptField

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
public ScriptField(String name, SearchScript script, boolean ignoreException) {
    this.name = name;
    this.script = script;
    this.ignoreException = ignoreException;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:ScriptFieldsContext.java


示例20: script

import org.elasticsearch.script.SearchScript; //导入依赖的package包/类
public SearchScript script() {
    return this.script;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ScriptFieldsContext.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Mode类代码示例发布时间:2022-05-22
下一篇:
Java AuthorizationException类代码示例发布时间: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