LUCENE-4704: Make join queries override hashcode and equals methods.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1439166 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Martijn van Groningen 2013-01-27 20:14:02 +00:00
parent d893b772a7
commit 6b3823e6a3
4 changed files with 62 additions and 2 deletions

View File

@ -104,6 +104,9 @@ Bug Fixes
degrees and barely any height, it would generate so many indexed terms
(> 500k) that it could even cause an OutOfMemoryError. Fixed. (David Smiley)
* LUCENE-4704: Make join queries override hashcode and equals methods.
(Martijn van Groningen)
======================= Lucene 4.1.0 =======================
Changes in backwards compatibility policy

View File

@ -71,7 +71,7 @@ public final class JoinUtil {
case None:
TermsCollector termsCollector = TermsCollector.create(fromField, multipleValuesPerDocument);
fromSearcher.search(fromQuery, termsCollector);
return new TermsQuery(toField, termsCollector.getCollectorTerms());
return new TermsQuery(toField, fromQuery, termsCollector.getCollectorTerms());
case Total:
case Max:
case Avg:

View File

@ -92,6 +92,35 @@ class TermsIncludingScoreQuery extends Query {
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} if (!super.equals(obj)) {
return false;
} if (getClass() != obj.getClass()) {
return false;
}
TermsIncludingScoreQuery other = (TermsIncludingScoreQuery) obj;
if (!field.equals(other.field)) {
return false;
}
if (!unwrittenOriginalQuery.equals(other.unwrittenOriginalQuery)) {
return false;
}
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result += prime * field.hashCode();
result += prime * unwrittenOriginalQuery.hashCode();
return result;
}
@Override
public Weight createWeight(IndexSearcher searcher) throws IOException {
final Weight originalWeight = originalQuery.createWeight(searcher);

View File

@ -21,6 +21,7 @@ import org.apache.lucene.index.FilteredTermsEnum;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefHash;
@ -37,13 +38,15 @@ import java.util.Comparator;
class TermsQuery extends MultiTermQuery {
private final BytesRefHash terms;
private final Query fromQuery; // Used for equals() only
/**
* @param field The field that should contain terms that are specified in the previous parameter
* @param terms The terms that matching documents should have. The terms must be sorted by natural order.
*/
TermsQuery(String field, BytesRefHash terms) {
TermsQuery(String field, Query fromQuery, BytesRefHash terms) {
super(field);
this.fromQuery = fromQuery;
this.terms = terms;
}
@ -63,6 +66,31 @@ class TermsQuery extends MultiTermQuery {
'}';
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} if (!super.equals(obj)) {
return false;
} if (getClass() != obj.getClass()) {
return false;
}
TermsQuery other = (TermsQuery) obj;
if (!fromQuery.equals(other.fromQuery)) {
return false;
}
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result += prime * fromQuery.hashCode();
return result;
}
static class SeekingTermSetTermsEnum extends FilteredTermsEnum {
private final BytesRefHash terms;