diff --git a/lucene/core/src/java/org/apache/lucene/search/DocTermOrdsRewriteMethod.java b/lucene/core/src/java/org/apache/lucene/search/DocTermOrdsRewriteMethod.java index 68ef562c7e0..d25318402e5 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DocTermOrdsRewriteMethod.java +++ b/lucene/core/src/java/org/apache/lucene/search/DocTermOrdsRewriteMethod.java @@ -163,4 +163,20 @@ public final class DocTermOrdsRewriteMethod extends MultiTermQuery.RewriteMethod }; } } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return true; + } + + @Override + public int hashCode() { + return 877; + } } diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldCacheRewriteMethod.java b/lucene/core/src/java/org/apache/lucene/search/FieldCacheRewriteMethod.java index 3d6c0391210..84f6092a3db 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FieldCacheRewriteMethod.java +++ b/lucene/core/src/java/org/apache/lucene/search/FieldCacheRewriteMethod.java @@ -162,4 +162,20 @@ public final class FieldCacheRewriteMethod extends MultiTermQuery.RewriteMethod }; } } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return true; + } + + @Override + public int hashCode() { + return 641; + } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDocTermOrdsRewriteMethod.java b/lucene/core/src/test/org/apache/lucene/search/TestDocTermOrdsRewriteMethod.java index a8bc0e48cb1..c1557be391e 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDocTermOrdsRewriteMethod.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDocTermOrdsRewriteMethod.java @@ -126,4 +126,19 @@ public class TestDocTermOrdsRewriteMethod extends LuceneTestCase { CheckHits.checkEqual(inverted, invertedDocs.scoreDocs, docValuesDocs.scoreDocs); } + + public void testEquals() throws Exception { + RegexpQuery a1 = new RegexpQuery(new Term(fieldName, "[aA]"), RegExp.NONE); + RegexpQuery a2 = new RegexpQuery(new Term(fieldName, "[aA]"), RegExp.NONE); + RegexpQuery b = new RegexpQuery(new Term(fieldName, "[bB]"), RegExp.NONE); + assertEquals(a1, a2); + assertFalse(a1.equals(b)); + + a1.setRewriteMethod(new DocTermOrdsRewriteMethod()); + a2.setRewriteMethod(new DocTermOrdsRewriteMethod()); + b.setRewriteMethod(new DocTermOrdsRewriteMethod()); + assertEquals(a1, a2); + assertFalse(a1.equals(b)); + QueryUtils.check(a1); + } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFieldCacheRewriteMethod.java b/lucene/core/src/test/org/apache/lucene/search/TestFieldCacheRewriteMethod.java index 32d1944e09c..1d127c7d6c2 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestFieldCacheRewriteMethod.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestFieldCacheRewriteMethod.java @@ -41,4 +41,19 @@ public class TestFieldCacheRewriteMethod extends TestRegexpRandom2 { CheckHits.checkEqual(fieldCache, fieldCacheDocs.scoreDocs, filterDocs.scoreDocs); } + + public void testEquals() throws Exception { + RegexpQuery a1 = new RegexpQuery(new Term(fieldName, "[aA]"), RegExp.NONE); + RegexpQuery a2 = new RegexpQuery(new Term(fieldName, "[aA]"), RegExp.NONE); + RegexpQuery b = new RegexpQuery(new Term(fieldName, "[bB]"), RegExp.NONE); + assertEquals(a1, a2); + assertFalse(a1.equals(b)); + + a1.setRewriteMethod(new FieldCacheRewriteMethod()); + a2.setRewriteMethod(new FieldCacheRewriteMethod()); + b.setRewriteMethod(new FieldCacheRewriteMethod()); + assertEquals(a1, a2); + assertFalse(a1.equals(b)); + QueryUtils.check(a1); + } }