diff --git a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java index 2f0d2399aa640..3215759b59259 100644 --- a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java +++ b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java @@ -44,6 +44,7 @@ import org.apache.lucene.search.Collector; import org.apache.lucene.search.CollectorManager; import org.apache.lucene.search.ConjunctionUtils; +import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; @@ -257,8 +258,15 @@ public void search( @Override public void search(Query query, Collector collector) throws IOException { - super.search(query, collector); - searchContext.bucketCollectorProcessor().processPostCollection(collector); + // TODO : Remove when switching to use the @org.apache.lucene.search.IndexSearcher#search(Query, CollectorManager) variant from + // @org.opensearch.search.query.QueryPhase#searchWithCollector which then calls the overridden + // search(LeafReaderContextPartition[] partitions, Weight weight, Collector collector) + query = collector.scoreMode().needsScores() ? rewrite(query) : rewrite(new ConstantScoreQuery(query)); + Weight weight = createWeight(query, collector.scoreMode(), 1); + LeafReaderContextPartition[] partitions = (getLeafContexts() == null) + ? new LeafReaderContextPartition[0] + : getLeafContexts().stream().map(LeafReaderContextPartition::createForEntireSegment).toArray(LeafReaderContextPartition[]::new); + search(partitions, weight, collector); } public void search( @@ -297,6 +305,7 @@ protected void search(LeafReaderContextPartition[] partitions, Weight weight, Co searchLeaf(partition.ctx, partition.minDocId, partition.maxDocId, weight, collector); } } + // TODO : Make this a responsibility for the callers rather than implicitly getting it done here ? searchContext.bucketCollectorProcessor().processPostCollection(collector); } catch (Throwable t) { searchContext.indexShard().getSearchOperationListener().onFailedSliceExecution(searchContext);