benwtrent commented on code in PR #12072:
URL: https://github.com/apache/lucene/pull/12072#discussion_r1067491908
##########
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 would make the same change to the main rewrite method. it simplifies
things further quite a bit, even if fixing rewriteNoScoring is already fixing
the exponential runtime issue.
I am not sure where you would want to make this change? I suppose I am
dense...
I am guessing right here:
https://github.com/apache/lucene/blob/7e0b142afeed676c4fc6dc40bbc7fcd277df5c34/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java#L287
The whole point is to wrap that query as a ConstantScore query. I guess you
don't want it wrapped if its boolean and short circuit that to be a
rewriteNoScoring. I was trying something along these lines, but then the inner
query never got rewritten in the `MUST` case...which was troubling.
But, we can already remove the IndexSearch from the method, which I am doing
now in a following commit.
--
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]