javanna commented on code in PR #16001:
URL: https://github.com/apache/lucene/pull/16001#discussion_r3180153624
##########
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:
Thanks. It was not a matter of structure on my end, more that I assumed the
existing logic was there for good reasons that I could not entirely explain,
and changing it may cause issues. We do rewrite to the constant score query,
and I wondered why we'd need to forcibly wrap again ahead of the weight
creation / additional rewrite.
Looking at history, I see the change that introduced the duplicated rewrite
was #13036 . That one did not touch the weight creation logic, but it probably
should have in the first place, to remove the additional wrapping and prevent
duplicated rewrite.
--
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]