Java Code Examples for org.elasticsearch.search.internal.SearchContext#rescore()
The following examples show how to use
org.elasticsearch.search.internal.SearchContext#rescore() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExplainFetchSubPhase.java From Elasticsearch with Apache License 2.0 | 6 votes |
@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); } }
Example 2
Source File: RescorePhase.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void execute(SearchContext context) { try { TopDocs topDocs = context.queryResult().topDocs(); for (RescoreSearchContext ctx : context.rescore()) { topDocs = ctx.rescorer().rescore(topDocs, context, ctx); } context.queryResult().topDocs(topDocs); } catch (IOException e) { throw new ElasticsearchException("Rescore Phase Failed", e); } }
Example 3
Source File: TransportExplainAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@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(); } }