javanna commented on code in PR #16001:
URL: https://github.com/apache/lucene/pull/16001#discussion_r3172796316


##########
lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java:
##########
@@ -514,7 +516,12 @@ public int count(Query query) throws IOException {
         return countTerm1 + countTerm2 - count(queries[2]);
       }
     }
-    return search(new ConstantScoreQuery(query), new 
TotalHitCountCollectorManager(getSlices()));
+
+    // Use the already-rewritten query directly, avoiding a redundant rewrite 
in search(query, collector)
+    var collectorManager = new TotalHitCountCollectorManager(getSlices());
+    var firstCollector = collectorManager.newCollector();
+    final Weight weight = createWeight(query, firstCollector.scoreMode(), 1);

Review Comment:
   to be exactly the same as before, shouldn't the weight be created providing 
`new ConstantScoreQuery(innerQuery)` ? Not sure if there are edge cases around 
this, but it seems like the rewritten query may not be a constant score query, 
in which case we would still wrap it here with a constant score query? Am I 
reading this correctly?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to