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


##########
lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java:
##########
@@ -203,9 +203,18 @@ BooleanQuery rewriteNoScoring(IndexSearcher indexSearcher) 
throws IOException {
 
     for (BooleanClause clause : clauses) {
       Query query = clause.getQuery();
-      Query rewritten = new ConstantScoreQuery(query).rewrite(indexSearcher);
-      if (rewritten instanceof ConstantScoreQuery) {
-        rewritten = ((ConstantScoreQuery) rewritten).getQuery();
+      // NOTE: rewritingNoScoring() should not call rewrite(), otherwise this
+      // method could run in exponential time with the depth of the query as
+      // every new level would rewrite 2x more than its parent level.
+      Query rewritten = query;
+      if (query instanceof BoostQuery) {
+        rewritten = ((BoostQuery) query).getQuery();
+      }
+      if (query instanceof ConstantScoreQuery) {
+        rewritten = ((ConstantScoreQuery) query).getQuery();
+      }
+      if (query instanceof BooleanQuery) {
+        rewritten = ((BooleanQuery) query).rewriteNoScoring(indexSearcher);

Review Comment:
   > I am guessing right here:
   
   yes that is what I had in mind. I was thinking the logic is exactly the same 
as what we have in rewriteNoScoring and we should be able to align the two. I 
have observed even less intermediate rewriting in my tests with that additional 
change. If it complicates things it's not required, I was assuming it does not.
   
   > But, we can already remove the IndexSearch from the method
   
   That's great. It basically enforces that we don't call rewrite (the note you 
added)  cause we no longer have a searcher to provide to it.



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