lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r359078 - in /lucene/java/trunk/src: java/org/apache/lucene/search/regex/ java/org/apache/lucene/search/spans/ test/org/apache/lucene/search/spans/
Date Mon, 26 Dec 2005 17:12:30 GMT
Author: yonik
Date: Mon Dec 26 09:12:16 2005
New Revision: 359078

URL: http://svn.apache.org/viewcvs?rev=359078&view=rev
Log:
implement, correct, improve hashcodes: LUCENE-460

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java Mon Dec
26 09:12:16 2005
@@ -65,15 +65,13 @@
 
   public boolean equals(Object o) {
     if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-
+    if (!(o instanceof TermQuery)) return false;
     final SpanRegexQuery that = (SpanRegexQuery) o;
-
     return term.equals(that.term) && getBoost() == that.getBoost();
   }
 
   public int hashCode() {
-    return term.hashCode();
+    return term.hashCode() ^ Float.floatToRawIntBits(getBoost()) ^ 0x4BCEF3A9;
   }
 
   public String toString(String field) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java Mon Dec
26 09:12:16 2005
@@ -105,4 +105,23 @@
       return this;                         // no clauses rewrote
     }
   }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof SpanFirstQuery)) return false;
+
+    SpanFirstQuery other = (SpanFirstQuery)o;
+    return this.end == other.end
+         && this.match.equals(other.match)
+         && this.getBoost() == other.getBoost();
+  }
+
+  public int hashCode() {
+    int h = match.hashCode();
+    h ^= (h << 8) | (h >>> 25);  // reversible
+    h ^= Float.floatToRawIntBits(getBoost()) ^ end;
+    return h;
+  }
+
+
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Mon Dec 26
09:12:16 2005
@@ -134,14 +134,13 @@
   /** Returns true iff <code>o</code> is equal to this. */
   public boolean equals(Object o) {
     if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
+    if (!(o instanceof SpanNearQuery)) return false;
 
     final SpanNearQuery spanNearQuery = (SpanNearQuery) o;
 
     if (inOrder != spanNearQuery.inOrder) return false;
     if (slop != spanNearQuery.slop) return false;
     if (!clauses.equals(spanNearQuery.clauses)) return false;
-    if (!field.equals(spanNearQuery.field)) return false;
 
     return getBoost() == spanNearQuery.getBoost();
   }
@@ -149,9 +148,13 @@
   public int hashCode() {
     int result;
     result = clauses.hashCode();
-    result += slop * 29;
-    result +=  (inOrder ? 1 : 0);
-    result ^= field.hashCode();
+    // Mix bits before folding in things like boost, since it could cancel the
+    // last element of clauses.  This particular mix also serves to
+    // differentiate SpanNearQuery hashcodes from others.
+    result ^= (result << 14) | (result >>> 19);  // reversible
+    result += Float.floatToRawIntBits(getBoost());
+    result += slop;
+    result ^= (inOrder ? 0x99AFD3BD : 0);
     return result;
   }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java Mon Dec 26
09:12:16 2005
@@ -151,4 +151,24 @@
     }
   }
 
+    /** Returns true iff <code>o</code> is equal to this. */
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof SpanNotQuery)) return false;
+
+    SpanNotQuery other = (SpanNotQuery)o;
+    return this.include.equals(other.include)
+            && this.exclude.equals(other.exclude)
+            && this.getBoost() == other.getBoost();
+  }
+
+  public int hashCode() {
+    int h = include.hashCode();
+    h = (h<<1) | (h >>> 31);  // rotate left
+    h ^= include.hashCode();
+    h = (h<<1) | (h >>> 31);  // rotate left
+    h ^= Float.floatToRawIntBits(getBoost());
+    return h;
+  }
+
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java Mon Dec 26
09:12:16 2005
@@ -113,10 +113,10 @@
   }
 
   public int hashCode() {
-    int result;
-    result = clauses.hashCode();
-    result = 29 * result + field.hashCode();
-    return result;
+    int h = clauses.hashCode();
+    h ^= (h << 10) | (h >>> 23);
+    h ^= Float.floatToRawIntBits(getBoost());
+    return h;
   }
 
   private class SpanQueue extends PriorityQueue {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestBasics.java Mon Dec 26 09:12:16
2005
@@ -72,7 +72,7 @@
        578, 579, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 770, 771,
        772, 773, 774, 775, 776, 777, 778, 779, 870, 871, 872, 873, 874, 875,
        876, 877, 878, 879, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979});
-  }
+    }
 
   public void testTerm2() throws Exception {
     Query query = new TermQuery(new Term("field", "seventish"));
@@ -120,6 +120,10 @@
 
     assertTrue(searcher.explain(query, 77).getValue() > 0.0f);
     assertTrue(searcher.explain(query, 977).getValue() > 0.0f);
+
+    QueryUtils.check(term1);
+    QueryUtils.check(term2);
+    QueryUtils.checkUnequal(term1,term2);
   }
 
   public void testSpanNearUnordered() throws Exception {
@@ -264,5 +268,6 @@
 
   private void checkHits(Query query, int[] results) throws IOException {
     CheckHits.checkHits(query, "field", searcher, results);
+    QueryUtils.check(query);
   }
 }



Mime
View raw message