lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r763857 - in /lucene/java/trunk/contrib/queries/src: java/org/apache/lucene/search/ test/org/apache/lucene/search/
Date Fri, 10 Apr 2009 02:21:04 GMT
Author: markrmiller
Date: Fri Apr 10 02:21:04 2009
New Revision: 763857

URL: http://svn.apache.org/viewvc?rev=763857&view=rev
Log:
Contrib queries package Query implementations do not override equals()

Added:
    lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/BoostingQueryTest.java
Modified:
    lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java
    lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java
    lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java

Modified: lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java?rev=763857&r1=763856&r2=763857&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java
(original)
+++ lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java
Fri Apr 10 02:21:04 2009
@@ -83,6 +83,38 @@
       return result;
     }
 
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + Float.floatToIntBits(boost);
+      result = prime * result + ((context == null) ? 0 : context.hashCode());
+      result = prime * result + ((match == null) ? 0 : match.hashCode());
+      return result;
+    }
+
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      BoostingQuery other = (BoostingQuery) obj;
+      if (Float.floatToIntBits(boost) != Float.floatToIntBits(other.boost))
+        return false;
+      if (context == null) {
+        if (other.context != null)
+          return false;
+      } else if (!context.equals(other.context))
+        return false;
+      if (match == null) {
+        if (other.match != null)
+          return false;
+      } else if (!match.equals(other.match))
+        return false;
+      return true;
+    }
+
     public String toString(String field) {
       return match.toString(field) + "/" + context.toString(field);
     }

Modified: lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java?rev=763857&r1=763856&r2=763857&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java
(original)
+++ lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java
Fri Apr 10 02:21:04 2009
@@ -57,8 +57,45 @@
     ScoreTermQueue q;
     int MAX_VARIANTS_PER_TERM=50;
     boolean ignoreTF=false;
+    private int maxNumTerms;
+
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((analyzer == null) ? 0 : analyzer.hashCode());
+      result = prime * result
+          + ((fieldVals == null) ? 0 : fieldVals.hashCode());
+      result = prime * result + (ignoreTF ? 1231 : 1237);
+      result = prime * result + maxNumTerms;
+      return result;
+    }
+
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      FuzzyLikeThisQuery other = (FuzzyLikeThisQuery) obj;
+      if (analyzer == null) {
+        if (other.analyzer != null)
+          return false;
+      } else if (!analyzer.equals(other.analyzer))
+        return false;
+      if (fieldVals == null) {
+        if (other.fieldVals != null)
+          return false;
+      } else if (!fieldVals.equals(other.fieldVals))
+        return false;
+      if (ignoreTF != other.ignoreTF)
+        return false;
+      if (maxNumTerms != other.maxNumTerms)
+        return false;
+      return true;
+    }
+
 
-    
     /**
      * 
      * @param maxNumTerms The total number of terms clauses that will appear once rewritten
as a BooleanQuery
@@ -68,6 +105,7 @@
     {
         q=new ScoreTermQueue(maxNumTerms);
         this.analyzer=analyzer;
+        this.maxNumTerms = maxNumTerms;
     }
 
     class FieldVals
@@ -83,6 +121,46 @@
 			prefixLength = length;
 			this.queryString = queryString;
 		}
+
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result
+          + ((fieldName == null) ? 0 : fieldName.hashCode());
+      result = prime * result + Float.floatToIntBits(minSimilarity);
+      result = prime * result + prefixLength;
+      result = prime * result
+          + ((queryString == null) ? 0 : queryString.hashCode());
+      return result;
+    }
+
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      FieldVals other = (FieldVals) obj;
+      if (fieldName == null) {
+        if (other.fieldName != null)
+          return false;
+      } else if (!fieldName.equals(other.fieldName))
+        return false;
+      if (Float.floatToIntBits(minSimilarity) != Float
+          .floatToIntBits(other.minSimilarity))
+        return false;
+      if (prefixLength != other.prefixLength)
+        return false;
+      if (queryString == null) {
+        if (other.queryString != null)
+          return false;
+      } else if (!queryString.equals(other.queryString))
+        return false;
+      return true;
+    }
+    
+
     	
     }
     

Added: lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/BoostingQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/BoostingQueryTest.java?rev=763857&view=auto
==============================================================================
--- lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/BoostingQueryTest.java
(added)
+++ lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/BoostingQueryTest.java
Fri Apr 10 02:21:04 2009
@@ -0,0 +1,16 @@
+package org.apache.lucene.search;
+
+import org.apache.lucene.index.Term;
+
+import junit.framework.TestCase;
+
+public class BoostingQueryTest extends TestCase {
+  public void testBoostingQueryEquals() {
+    TermQuery q1 = new TermQuery(new Term("subject:", "java"));
+    TermQuery q2 = new TermQuery(new Term("subject:", "java"));
+    assertEquals("Two TermQueries with same attributes should be equal", q1, q2);
+    BoostingQuery bq1 = new BoostingQuery(q1, q2, 0.1f);
+    BoostingQuery bq2 = new BoostingQuery(q1, q2, 0.1f);
+    assertEquals("BoostingQuery with same attributes is not equal", bq1, bq2);
+  }
+}

Modified: lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java?rev=763857&r1=763856&r2=763857&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java
(original)
+++ lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java
Fri Apr 10 02:21:04 2009
@@ -111,4 +111,14 @@
 		Document doc=searcher.doc(sd[0].doc);
 		assertEquals("Should match most similar when using 2 words", "2",doc.get("id"));
 	}
+	
+	public void testFuzzyLikeThisQueryEquals() {
+	  Analyzer analyzer = new WhitespaceAnalyzer();
+    FuzzyLikeThisQuery fltq1 = new FuzzyLikeThisQuery(10, analyzer);
+    fltq1.addTerms("javi", "subject", 0.5f, 2);
+    FuzzyLikeThisQuery fltq2 = new FuzzyLikeThisQuery(10, analyzer);
+    fltq2.addTerms("javi", "subject", 0.5f, 2);
+    assertEquals("FuzzyLikeThisQuery with same attributes is not equal", fltq1,
+        fltq2);
+  } 
 }



Mime
View raw message