LUCENE-6333: fix hashcode impl for TermsQuery

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1666528 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2015-03-13 17:56:34 +00:00
parent d4cba95df4
commit fd86381062
2 changed files with 14 additions and 0 deletions

View File

@ -208,6 +208,11 @@ public class TermsQuery extends Query implements Accountable {
return false;
}
@Override
public int hashCode() {
return super.hashCode() ^ this.hashCode;
}
@Override
public String toString(String defaultField) {
StringBuilder builder = new StringBuilder();

View File

@ -166,6 +166,15 @@ public class TermsQueryTest extends LuceneTestCase {
assertFalse(right.equals(notEqual));
}
}
TermsQuery tq1 = new TermsQuery(new Term("thing", "apple"));
TermsQuery tq2 = new TermsQuery(new Term("thing", "orange"));
assertFalse(tq1.hashCode() == tq2.hashCode());
// different fields with the same term should have differing hashcodes
tq1 = new TermsQuery(new Term("thing1", "apple"));
tq2 = new TermsQuery(new Term("thing2", "apple"));
assertFalse(tq1.hashCode() == tq2.hashCode());
}
public void testSingleFieldEquals() {