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


##########
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:
   Without checking for `BooleanQuery`, the number of rewrites on the innermost 
query are no longer `1` in the `MUST` clause case. 
   
   Removing the recursive `rewriteNoScoring` here, makes the total number of 
rewrites on the innermost query to equal the depth in the `MUST` clause, and 
2*depth in the `SHOULD` clause. 
   
   @jpountz what say you?



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