From e6a539ba541bedcb4f534b5a0f2577ba82be549f Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 5 Mar 2019 12:51:55 +0100 Subject: [PATCH] Minor Cleanups in QueryPhase (#39680) * Soften redundant cast to allow use of `DeterministicTaskQueue` in this class for #39504 * Remove two redundant variables and lower visibility in two possible spots * Make field `final` --- .../elasticsearch/search/query/QueryPhase.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/server/src/main/java/org/elasticsearch/search/query/QueryPhase.java index f0fdbf0c72670..8f933b28d94c1 100644 --- a/server/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/server/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -40,7 +40,6 @@ import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore; -import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor; import org.elasticsearch.common.util.concurrent.QueueResizingEsThreadPoolExecutor; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.SearchPhase; @@ -59,6 +58,7 @@ import org.elasticsearch.threadpool.ThreadPool; import java.util.LinkedList; +import java.util.concurrent.ExecutorService; import java.util.function.Consumer; import static org.elasticsearch.search.query.QueryCollectorContext.createCancellableCollectorContext; @@ -78,7 +78,7 @@ public class QueryPhase implements SearchPhase { private final AggregationPhase aggregationPhase; private final SuggestPhase suggestPhase; - private RescorePhase rescorePhase; + private final RescorePhase rescorePhase; public QueryPhase() { this.aggregationPhase = new AggregationPhase(); @@ -157,11 +157,10 @@ static boolean execute(SearchContext searchContext, // now this gets interesting: since we sort in index-order, we can directly // skip to the desired doc if (after != null) { - BooleanQuery bq = new BooleanQuery.Builder() + query = new BooleanQuery.Builder() .add(query, BooleanClause.Occur.MUST) .add(new MinDocQuery(after.doc + 1), BooleanClause.Occur.FILTER) .build(); - query = bq; } // ... and stop collecting after ${size} matches searchContext.terminateAfter(searchContext.size()); @@ -169,11 +168,10 @@ static boolean execute(SearchContext searchContext, // now this gets interesting: since the search sort is a prefix of the index sort, we can directly // skip to the desired doc if (after != null) { - BooleanQuery bq = new BooleanQuery.Builder() + query = new BooleanQuery.Builder() .add(query, BooleanClause.Occur.MUST) .add(new SearchAfterSortedDocQuery(searchContext.sort().sort, (FieldDoc) after), BooleanClause.Occur.FILTER) .build(); - query = bq; } } } @@ -289,8 +287,7 @@ static boolean execute(SearchContext searchContext, for (QueryCollectorContext ctx : collectors) { ctx.postProcess(result); } - EsThreadPoolExecutor executor = (EsThreadPoolExecutor) - searchContext.indexShard().getThreadPool().executor(ThreadPool.Names.SEARCH); + ExecutorService executor = searchContext.indexShard().getThreadPool().executor(ThreadPool.Names.SEARCH); if (executor instanceof QueueResizingEsThreadPoolExecutor) { QueueResizingEsThreadPoolExecutor rExecutor = (QueueResizingEsThreadPoolExecutor) executor; queryResult.nodeQueueSize(rExecutor.getCurrentQueueSize()); @@ -311,7 +308,7 @@ static boolean execute(SearchContext searchContext, * @param query The query to execute * @param sf The query sort */ - static boolean returnsDocsInOrder(Query query, SortAndFormats sf) { + private static boolean returnsDocsInOrder(Query query, SortAndFormats sf) { if (sf == null || Sort.RELEVANCE.equals(sf.sort)) { // sort by score // queries that return constant scores will return docs in index @@ -327,7 +324,7 @@ static boolean returnsDocsInOrder(Query query, SortAndFormats sf) { * Returns whether collection within the provided reader can be early-terminated if it sorts * with sortAndFormats. **/ - static boolean canEarlyTerminate(IndexReader reader, SortAndFormats sortAndFormats) { + private static boolean canEarlyTerminate(IndexReader reader, SortAndFormats sortAndFormats) { if (sortAndFormats == null || sortAndFormats.sort == null) { return false; }