mirror of https://github.com/apache/lucene.git
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:
parent
d893b772a7
commit
6b3823e6a3
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue