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


##########
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:
   I suppose your inquiry indirectly challenges my opinion that this method has 
structure, as you don't see it.  I recommend introducing a pair of `{ }` to 
scope the innerQuery & rewriteTwoClauseDisjunctionWithTermsForCount check so 
that the code down here can't reference it.
   
   I'd also like to comment that the inserted CSQ has some optimizations that 
rewrite will simplify.



-- 
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