Skip to content

Commit 750ec8b

Browse files
Minor Cleanups in QueryPhase (#39680) (#39694)
* 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`
1 parent 5cdea6e commit 750ec8b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

server/src/main/java/org/elasticsearch/search/query/QueryPhase.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.elasticsearch.action.search.SearchTask;
4141
import org.elasticsearch.common.lucene.Lucene;
4242
import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore;
43-
import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor;
4443
import org.elasticsearch.common.util.concurrent.QueueResizingEsThreadPoolExecutor;
4544
import org.elasticsearch.search.DocValueFormat;
4645
import org.elasticsearch.search.SearchPhase;
@@ -59,6 +58,7 @@
5958
import org.elasticsearch.threadpool.ThreadPool;
6059

6160
import java.util.LinkedList;
61+
import java.util.concurrent.ExecutorService;
6262
import java.util.function.Consumer;
6363

6464
import static org.elasticsearch.search.query.QueryCollectorContext.createCancellableCollectorContext;
@@ -78,7 +78,7 @@ public class QueryPhase implements SearchPhase {
7878

7979
private final AggregationPhase aggregationPhase;
8080
private final SuggestPhase suggestPhase;
81-
private RescorePhase rescorePhase;
81+
private final RescorePhase rescorePhase;
8282

8383
public QueryPhase() {
8484
this.aggregationPhase = new AggregationPhase();
@@ -157,23 +157,21 @@ static boolean execute(SearchContext searchContext,
157157
// now this gets interesting: since we sort in index-order, we can directly
158158
// skip to the desired doc
159159
if (after != null) {
160-
BooleanQuery bq = new BooleanQuery.Builder()
160+
query = new BooleanQuery.Builder()
161161
.add(query, BooleanClause.Occur.MUST)
162162
.add(new MinDocQuery(after.doc + 1), BooleanClause.Occur.FILTER)
163163
.build();
164-
query = bq;
165164
}
166165
// ... and stop collecting after ${size} matches
167166
searchContext.terminateAfter(searchContext.size());
168167
} else if (canEarlyTerminate(reader, searchContext.sort())) {
169168
// now this gets interesting: since the search sort is a prefix of the index sort, we can directly
170169
// skip to the desired doc
171170
if (after != null) {
172-
BooleanQuery bq = new BooleanQuery.Builder()
171+
query = new BooleanQuery.Builder()
173172
.add(query, BooleanClause.Occur.MUST)
174173
.add(new SearchAfterSortedDocQuery(searchContext.sort().sort, (FieldDoc) after), BooleanClause.Occur.FILTER)
175174
.build();
176-
query = bq;
177175
}
178176
}
179177
}
@@ -289,8 +287,7 @@ static boolean execute(SearchContext searchContext,
289287
for (QueryCollectorContext ctx : collectors) {
290288
ctx.postProcess(result);
291289
}
292-
EsThreadPoolExecutor executor = (EsThreadPoolExecutor)
293-
searchContext.indexShard().getThreadPool().executor(ThreadPool.Names.SEARCH);
290+
ExecutorService executor = searchContext.indexShard().getThreadPool().executor(ThreadPool.Names.SEARCH);
294291
if (executor instanceof QueueResizingEsThreadPoolExecutor) {
295292
QueueResizingEsThreadPoolExecutor rExecutor = (QueueResizingEsThreadPoolExecutor) executor;
296293
queryResult.nodeQueueSize(rExecutor.getCurrentQueueSize());
@@ -311,7 +308,7 @@ static boolean execute(SearchContext searchContext,
311308
* @param query The query to execute
312309
* @param sf The query sort
313310
*/
314-
static boolean returnsDocsInOrder(Query query, SortAndFormats sf) {
311+
private static boolean returnsDocsInOrder(Query query, SortAndFormats sf) {
315312
if (sf == null || Sort.RELEVANCE.equals(sf.sort)) {
316313
// sort by score
317314
// queries that return constant scores will return docs in index
@@ -327,7 +324,7 @@ static boolean returnsDocsInOrder(Query query, SortAndFormats sf) {
327324
* Returns whether collection within the provided <code>reader</code> can be early-terminated if it sorts
328325
* with <code>sortAndFormats</code>.
329326
**/
330-
static boolean canEarlyTerminate(IndexReader reader, SortAndFormats sortAndFormats) {
327+
private static boolean canEarlyTerminate(IndexReader reader, SortAndFormats sortAndFormats) {
331328
if (sortAndFormats == null || sortAndFormats.sort == null) {
332329
return false;
333330
}

0 commit comments

Comments
 (0)