當前位置: 首頁>>代碼示例>>Java>>正文


Java SearchContext.clearReleasables方法代碼示例

本文整理匯總了Java中org.elasticsearch.search.internal.SearchContext.clearReleasables方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchContext.clearReleasables方法的具體用法?Java SearchContext.clearReleasables怎麽用?Java SearchContext.clearReleasables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.search.internal.SearchContext的用法示例。


在下文中一共展示了SearchContext.clearReleasables方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hitExecute

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
    if (context.explain() == false) {
        return;
    }
    try {
        final int topLevelDocId = hitContext.hit().docId();
        Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);

        for (RescoreSearchContext rescore : context.rescore()) {
            explanation = rescore.rescorer().explain(topLevelDocId, context, rescore, explanation);
        }
        // we use the top level doc id, since we work with the top level searcher
        hitContext.hit().explanation(explanation);
    } catch (IOException e) {
        throw new FetchPhaseExecutionException(context, "Failed to explain doc [" + hitContext.hit().getType() + "#"
                + hitContext.hit().getId() + "]", e);
    } finally {
        context.clearReleasables(SearchContext.Lifetime.COLLECTION);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:ExplainFetchSubPhase.java

示例2: hitExecute

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
    try {
        final int topLevelDocId = hitContext.hit().docId();
        Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);
        
        for (RescoreSearchContext rescore : context.rescore()) {
            explanation = rescore.rescorer().explain(topLevelDocId, context, rescore, explanation);
        }
        // we use the top level doc id, since we work with the top level searcher
        hitContext.hit().explanation(explanation);
    } catch (IOException e) {
        throw new FetchPhaseExecutionException(context, "Failed to explain doc [" + hitContext.hit().type() + "#" + hitContext.hit().id() + "]", e);
    } finally {
        context.clearReleasables(SearchContext.Lifetime.COLLECTION);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:18,代碼來源:ExplainFetchSubPhase.java

示例3: cleanContext

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
private void cleanContext(SearchContext context) {
    try {
        context.clearReleasables(Lifetime.PHASE);
        context.setTask(null);
    } finally {
        context.decRef();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:SearchService.java

示例4: hitsExecute

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) {
    if (hits.length == 0 ||
        // in case the request has only suggest, parsed query is null
        context.parsedQuery() == null) {
        return;
    }
    hits = hits.clone(); // don't modify the incoming hits
    Arrays.sort(hits, (a, b) -> Integer.compare(a.docId(), b.docId()));
    @SuppressWarnings("unchecked")
    List<String>[] matchedQueries = new List[hits.length];
    for (int i = 0; i < matchedQueries.length; ++i) {
        matchedQueries[i] = new ArrayList<>();
    }

    Map<String, Query> namedQueries = new HashMap<>(context.parsedQuery().namedFilters());
    if (context.parsedPostFilter() != null) {
        namedQueries.putAll(context.parsedPostFilter().namedFilters());
    }

    try {
        for (Map.Entry<String, Query> entry : namedQueries.entrySet()) {
            String name = entry.getKey();
            Query query = entry.getValue();
            int readerIndex = -1;
            int docBase = -1;
            Weight weight = context.searcher().createNormalizedWeight(query, false);
            Bits matchingDocs = null;
            final IndexReader indexReader = context.searcher().getIndexReader();
            for (int i = 0; i < hits.length; ++i) {
                SearchHit hit = hits[i];
                int hitReaderIndex = ReaderUtil.subIndex(hit.docId(), indexReader.leaves());
                if (readerIndex != hitReaderIndex) {
                    readerIndex = hitReaderIndex;
                    LeafReaderContext ctx = indexReader.leaves().get(readerIndex);
                    docBase = ctx.docBase;
                    // scorers can be costly to create, so reuse them across docs of the same segment
                    Scorer scorer = weight.scorer(ctx);
                    matchingDocs = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), scorer);
                }
                if (matchingDocs.get(hit.docId() - docBase)) {
                    matchedQueries[i].add(name);
                }
            }
        }
        for (int i = 0; i < hits.length; ++i) {
            hits[i].matchedQueries(matchedQueries[i].toArray(new String[matchedQueries[i].size()]));
        }
    } catch (IOException e) {
        throw ExceptionsHelper.convertToElastic(e);
    } finally {
        context.clearReleasables(Lifetime.COLLECTION);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:55,代碼來源:MatchedQueriesFetchSubPhase.java

示例5: 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


注:本文中的org.elasticsearch.search.internal.SearchContext.clearReleasables方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。