uschindler commented on code in PR #12197: URL: https://github.com/apache/lucene/pull/12197#discussion_r1186020366
########## lucene/core/src/java/org/apache/lucene/search/Query.java: ########## @@ -77,10 +85,28 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo * <p>Callers are expected to call <code>rewrite</code> multiple times if necessary, until the * rewritten query is the same as the original query. * + * @deprecated Use {@link Query#rewrite(IndexSearcher)} * @see IndexSearcher#rewrite(Query) */ + @Deprecated public Query rewrite(IndexReader reader) throws IOException { - return this; + return isDeprecatedRewriteMethodOverridden ? this : rewrite(new IndexSearcher(reader)); Review Comment: I was also thinking about this, but yes, there's no way to prevent this. The problem why we need VirtualMethod here is exactly because a query could override one or the other method. The additional complexity is then if the overriden method calls super(). In that case it has to also delegate to the counterpart. This is highly complex and we should try to avoid too many loops (`this.a() -> super.a() -> super.b() -> super.a()`). But the current code should be fine, IMHO. Do we have a test like `TestVirtualMethod` class? ########## lucene/core/src/java/org/apache/lucene/search/Query.java: ########## @@ -45,6 +46,13 @@ */ public abstract class Query { + static final VirtualMethod<Query> oldMethod = Review Comment: Yes looks correct! I would make all those 3 fields private, no need to make them visisble - not even for subclasses. -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org