4040import org .elasticsearch .action .search .SearchTask ;
4141import org .elasticsearch .common .lucene .Lucene ;
4242import org .elasticsearch .common .lucene .search .TopDocsAndMaxScore ;
43- import org .elasticsearch .common .util .concurrent .EsThreadPoolExecutor ;
4443import org .elasticsearch .common .util .concurrent .QueueResizingEsThreadPoolExecutor ;
4544import org .elasticsearch .search .DocValueFormat ;
4645import org .elasticsearch .search .SearchPhase ;
5958import org .elasticsearch .threadpool .ThreadPool ;
6059
6160import java .util .LinkedList ;
61+ import java .util .concurrent .ExecutorService ;
6262import java .util .function .Consumer ;
6363
6464import 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