Skip to content

Apache Lucene open-source search software

add .equals/.hashCode to SpanTermQuery to allow comparison and collections to work logically. The other SpanQuery subclasses should probably have a similar adjustment and I will take care of those as I run into cases where it is necessary

Erik Hatcher79bc8a459363
diff --git a/src/java/org/apache/lucene/search/spans/SpanTermQuery.java b/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
index 0035fd7cbe6..e6d1ba55e48 100644
--- a/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
@@ -50,6 +50,20 @@ public class SpanTermQuery extends SpanQuery {
return term.toString();
}
+ /** Returns true iff <code>o</code> is equal to this. */
+ public boolean equals(Object o) {
+ if (!(o instanceof SpanTermQuery))
+ return false;
+ SpanTermQuery other = (SpanTermQuery)o;
+ return (this.getBoost() == other.getBoost())
+ && this.term.equals(other.term);
+ }
+
+ /** Returns a hash code value for this object.*/
+ public int hashCode() {
+ return Float.floatToIntBits(getBoost()) ^ term.hashCode();
+ }
+
public Spans getSpans(final IndexReader reader) throws IOException {
return new Spans() {
private TermPositions positions = reader.termPositions(term);