javanna commented on code in PR #12072:
URL: https://github.com/apache/lucene/pull/12072#discussion_r1067468924
##########
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 believe that we can completely remove the check for boolean query (like
Adrien suggested). If we unwrap what's in the boost query the rewriteNoScoring
will be taken care of at the next round of rewrite if the inner query is a
constant score query.
That allows us to remove the IndexSearcher argument from this method.
--
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]