Apache Lucene open-source search software
LUCENE-7685: Remove equals/rewrite hacks from block join queries.
Adrien Grandc2f061d7cbcd
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex c91e7537512..032d8972de6 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -126,6 +126,10 @@ Bug Fixes* LUCENE-7692: PatternReplaceCharFilterFactory now implements MultiTermAware.(Adrien Grand)+* LUCENE-7685: ToParentBlockJoinQuery and ToChildBlockJoinQuery now use the+ rewritten child query in their equals and hashCode implementations.+ (Adrien Grand)+Improvements* LUCENE-7055: Added Weight#scorerSupplier, which allows to estimate the costdiff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.javaindex 0b5c19bc84a..50003ccb9cb 100644--- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java@@ -52,13 +52,6 @@ public class ToChildBlockJoinQuery extends Query {private final BitSetProducer parentsFilter;private final Query parentQuery;- // If we are rewritten, this is the original parentQuery we- // were passed; we use this for .equals() and- // .hashCode(). This makes rewritten query equal the- // original, so that user does not have to .rewrite() their- // query before searching:- private final Query origParentQuery;-/*** Create a ToChildBlockJoinQuery.*@@ -67,14 +60,6 @@ public class ToChildBlockJoinQuery extends Query {*/public ToChildBlockJoinQuery(Query parentQuery, BitSetProducer parentsFilter) {super();- this.origParentQuery = parentQuery;- this.parentQuery = parentQuery;- this.parentsFilter = parentsFilter;- }-- private ToChildBlockJoinQuery(Query origParentQuery, Query parentQuery, BitSetProducer parentsFilter) {- super();- this.origParentQuery = origParentQuery;this.parentQuery = parentQuery;this.parentsFilter = parentsFilter;}@@ -312,9 +297,7 @@ public class ToChildBlockJoinQuery extends Query {public Query rewrite(IndexReader reader) throws IOException {final Query parentRewrite = parentQuery.rewrite(reader);if (parentRewrite != parentQuery) {- return new ToChildBlockJoinQuery(parentQuery,- parentRewrite,- parentsFilter);+ return new ToChildBlockJoinQuery(parentRewrite, parentsFilter);} else {return super.rewrite(reader);}@@ -332,7 +315,7 @@ public class ToChildBlockJoinQuery extends Query {}private boolean equalsTo(ToChildBlockJoinQuery other) {- return origParentQuery.equals(other.origParentQuery) &&+ return parentQuery.equals(other.parentQuery) &&parentsFilter.equals(other.parentsFilter);}@@ -340,7 +323,7 @@ public class ToChildBlockJoinQuery extends Query {public int hashCode() {final int prime = 31;int hash = classHash();- hash = prime * hash + origParentQuery.hashCode();+ hash = prime * hash + parentQuery.hashCode();hash = prime * hash + parentsFilter.hashCode();return hash;}diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.javaindex 28374233bd0..0f1f7270367 100644--- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java@@ -67,13 +67,6 @@ public class ToParentBlockJoinQuery extends Query {private final BitSetProducer parentsFilter;private final Query childQuery;-- // If we are rewritten, this is the original childQuery we- // were passed; we use this for .equals() and- // .hashCode(). This makes rewritten query equal the- // original, so that user does not have to .rewrite() their- // query before searching:- private final Query origChildQuery;private final ScoreMode scoreMode;/** Create a ToParentBlockJoinQuery.@@ -85,15 +78,6 @@ public class ToParentBlockJoinQuery extends Query {**/public ToParentBlockJoinQuery(Query childQuery, BitSetProducer parentsFilter, ScoreMode scoreMode) {super();- this.origChildQuery = childQuery;- this.childQuery = childQuery;- this.parentsFilter = parentsFilter;- this.scoreMode = scoreMode;- }-- private ToParentBlockJoinQuery(Query origChildQuery, Query childQuery, BitSetProducer parentsFilter, ScoreMode scoreMode) {- super();- this.origChildQuery = origChildQuery;this.childQuery = childQuery;this.parentsFilter = parentsFilter;this.scoreMode = scoreMode;@@ -377,8 +361,7 @@ public class ToParentBlockJoinQuery extends Query {public Query rewrite(IndexReader reader) throws IOException {final Query childRewrite = childQuery.rewrite(reader);if (childRewrite != childQuery) {- return new ToParentBlockJoinQuery(origChildQuery,- childRewrite,+ return new ToParentBlockJoinQuery(childRewrite,parentsFilter,scoreMode);} else {@@ -398,7 +381,7 @@ public class ToParentBlockJoinQuery extends Query {}private boolean equalsTo(ToParentBlockJoinQuery other) {- return origChildQuery.equals(other.origChildQuery) &&+ return childQuery.equals(other.childQuery) &&parentsFilter.equals(other.parentsFilter) &&scoreMode == other.scoreMode;}@@ -407,7 +390,7 @@ public class ToParentBlockJoinQuery extends Query {public int hashCode() {final int prime = 31;int hash = classHash();- hash = prime * hash + origChildQuery.hashCode();+ hash = prime * hash + childQuery.hashCode();hash = prime * hash + scoreMode.hashCode();hash = prime * hash + parentsFilter.hashCode();return hash;