当前位置: 首页>>代码示例>>Java>>正文


Java SearchContext.removeCurrent方法代码示例

本文整理汇总了Java中org.elasticsearch.search.internal.SearchContext.removeCurrent方法的典型用法代码示例。如果您正苦于以下问题:Java SearchContext.removeCurrent方法的具体用法?Java SearchContext.removeCurrent怎么用?Java SearchContext.removeCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.search.internal.SearchContext的用法示例。


在下文中一共展示了SearchContext.removeCurrent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shardOperation

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
@Override
protected ShardExistsResponse shardOperation(ShardExistsRequest request) {
    IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
    IndexShard indexShard = indexService.shardSafe(request.shardId().id());

    SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.shardId().getIndex(), request.shardId().id());
    SearchContext context = new DefaultSearchContext(0,
            new ShardSearchLocalRequest(request.types(), request.nowInMillis(), request.filteringAliases()),
            shardTarget, indexShard.acquireSearcher("exists"), indexService, indexShard,
            scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher,
            SearchService.NO_TIMEOUT
    );
    SearchContext.setCurrent(context);

    try {
        if (request.minScore() != DEFAULT_MIN_SCORE) {
            context.minimumScore(request.minScore());
        }
        BytesReference source = request.querySource();
        if (source != null && source.length() > 0) {
            try {
                QueryParseContext.setTypes(request.types());
                context.parsedQuery(indexService.queryParserService().parseQuery(source));
            } finally {
                QueryParseContext.removeTypes();
            }
        }
        context.preProcess();
        try {
            boolean exists;
            try {
                exists = Lucene.exists(context.searcher(), context.query());
            } finally {
                context.clearReleasables(SearchContext.Lifetime.COLLECTION);
            }
            return new ShardExistsResponse(request.shardId(), exists);
        } catch (Exception e) {
            throw new QueryPhaseExecutionException(context, "failed to execute exists", e);
        }
    } finally {
        // this will also release the index searcher
        context.close();
        SearchContext.removeCurrent();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:46,代码来源:TransportExistsAction.java

示例2: shardOperation

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
@Override
protected ExplainResponse shardOperation(ExplainRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.shardSafe(shardId.id());
    Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id()));
    Engine.GetResult result = indexShard.get(new Engine.Get(false, uidTerm));
    if (!result.exists()) {
        return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), false);
    }

    SearchContext context = new DefaultSearchContext(
            0, new ShardSearchLocalRequest(new String[]{request.type()}, request.nowInMillis, request.filteringAlias()),
            null, result.searcher(), indexService, indexShard,
            scriptService, pageCacheRecycler,
            bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher,
            SearchService.NO_TIMEOUT
    );
    SearchContext.setCurrent(context);

    try {
        context.parsedQuery(indexService.queryParserService().parseQuery(request.source()));
        context.preProcess();
        int topLevelDocId = result.docIdAndVersion().docId + result.docIdAndVersion().context.docBase;
        Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);
        for (RescoreSearchContext ctx : context.rescore()) {
            Rescorer rescorer = ctx.rescorer();
            explanation = rescorer.explain(topLevelDocId, context, ctx, explanation);
        }
        if (request.fields() != null || (request.fetchSourceContext() != null && request.fetchSourceContext().fetchSource())) {
            // Advantage is that we're not opening a second searcher to retrieve the _source. Also
            // because we are working in the same searcher in engineGetResult we can be sure that a
            // doc isn't deleted between the initial get and this call.
            GetResult getResult = indexShard.getService().get(result, request.id(), request.type(), request.fields(), request.fetchSourceContext(), false);
            return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), true, explanation, getResult);
        } else {
            return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), true, explanation);
        }
    } catch (IOException e) {
        throw new ElasticsearchException("Could not explain", e);
    } finally {
        context.close();
        SearchContext.removeCurrent();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:45,代码来源:TransportExplainAction.java


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