lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject lucene-solr:branch_6x: LUCENE-7133: check field name in equals/hashCode for point queries
Date Wed, 23 Mar 2016 21:11:42 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 39270d9df -> 064f599cc


LUCENE-7133: check field name in equals/hashCode for point queries


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/064f599c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/064f599c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/064f599c

Branch: refs/heads/branch_6x
Commit: 064f599cc8becb6a7383b45b8effe0ae01711661
Parents: 39270d9
Author: Mike McCandless <mikemccand@apache.org>
Authored: Wed Mar 23 17:12:14 2016 -0400
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Wed Mar 23 17:12:43 2016 -0400

----------------------------------------------------------------------
 .../apache/lucene/search/PointInSetQuery.java   |  4 +-
 .../apache/lucene/search/PointRangeQuery.java   |  9 +++-
 .../apache/lucene/search/TestPointQueries.java  | 20 ++++++---
 .../flexible/standard/TestPointQueryParser.java |  2 +-
 .../document/LatLonPointDistanceQuery.java      |  2 +-
 .../document/LatLonPointInPolygonQuery.java     |  6 ++-
 .../lucene/document/TestBigIntegerPoint.java    |  6 ++-
 .../lucene/document/TestInetAddressPoint.java   |  6 ++-
 .../lucene/search/TestLatLonPointQueries.java   |  2 +-
 .../spatial/util/BaseGeoPointTestCase.java      | 43 ++++++++++++++++++++
 .../spatial3d/PointInGeo3DShapeQuery.java       |  4 ++
 .../apache/lucene/spatial3d/TestGeo3DPoint.java |  1 +
 12 files changed, 88 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
index bee864f..3314e29 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
@@ -304,6 +304,7 @@ public abstract class PointInSetQuery extends Query {
   @Override
   public final int hashCode() {
     int hash = super.hashCode();
+    hash = 31 * hash + field.hashCode();
     hash = 31 * hash + sortedPackedPointsHashCode;
     hash = 31 * hash + numDims;
     hash = 31 * hash + bytesPerDim;
@@ -314,7 +315,8 @@ public abstract class PointInSetQuery extends Query {
   public final boolean equals(Object other) {
     if (super.equals(other)) {
       final PointInSetQuery q = (PointInSetQuery) other;
-      return q.numDims == numDims &&
+      return q.field.equals(field) &&
+        q.numDims == numDims &&
         q.bytesPerDim == bytesPerDim &&
         q.sortedPackedPointsHashCode == sortedPackedPointsHashCode &&
         q.sortedPackedPoints.equals(sortedPackedPoints);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
index cfa644f..eb183e2 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
@@ -219,6 +219,7 @@ public abstract class PointRangeQuery extends Query {
   @Override
   public final int hashCode() {
     int hash = super.hashCode();
+    hash = 31 * hash + field.hashCode();
     hash = 31 * hash + Arrays.hashCode(lowerPoint);
     hash = 31 * hash + Arrays.hashCode(upperPoint);
     hash = 31 * hash + numDims;
@@ -233,6 +234,10 @@ public abstract class PointRangeQuery extends Query {
     }
 
     final PointRangeQuery q = (PointRangeQuery) other;
+    if (field.equals(q.field) == false) {
+      return false;
+    }
+
     if (q.numDims != numDims) {
       return false;
     }
@@ -241,11 +246,11 @@ public abstract class PointRangeQuery extends Query {
       return false;
     }
 
-    if (!Arrays.equals(lowerPoint, q.lowerPoint)) {
+    if (Arrays.equals(lowerPoint, q.lowerPoint) == false) {
       return false;
     }
     
-    if (!Arrays.equals(upperPoint, q.upperPoint)) {
+    if (Arrays.equals(upperPoint, q.upperPoint) == false) {
       return false;
     }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
index b4a586d..c2136c4 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
@@ -1896,11 +1896,14 @@ public class TestPointQueries extends LuceneTestCase {
   }
 
   public void testPointRangeEquals() {
-    Query q1 = IntPoint.newRangeQuery("a", 0, 1000);
-    Query q2 = IntPoint.newRangeQuery("a", 0, 1000);
+    Query q1, q2;
+
+    q1 = IntPoint.newRangeQuery("a", 0, 1000);
+    q2 = IntPoint.newRangeQuery("a", 0, 1000);
     assertEquals(q1, q2);
     assertEquals(q1.hashCode(), q2.hashCode());
     assertFalse(q1.equals(IntPoint.newRangeQuery("a", 1, 1000)));
+    assertFalse(q1.equals(IntPoint.newRangeQuery("b", 0, 1000)));
 
     q1 = LongPoint.newRangeQuery("a", 0, 1000);
     q2 = LongPoint.newRangeQuery("a", 0, 1000);
@@ -1933,11 +1936,14 @@ public class TestPointQueries extends LuceneTestCase {
   }
 
   public void testPointExactEquals() {
-    Query q1 = IntPoint.newExactQuery("a", 1000);
-    Query q2 = IntPoint.newExactQuery("a", 1000);
+    Query q1, q2;
+
+    q1 = IntPoint.newExactQuery("a", 1000);
+    q2 = IntPoint.newExactQuery("a", 1000);
     assertEquals(q1, q2);
     assertEquals(q1.hashCode(), q2.hashCode());
     assertFalse(q1.equals(IntPoint.newExactQuery("a", 1)));
+    assertFalse(q1.equals(IntPoint.newExactQuery("b", 1000)));
 
     q1 = LongPoint.newExactQuery("a", 1000);
     q2 = LongPoint.newExactQuery("a", 1000);
@@ -1969,11 +1975,13 @@ public class TestPointQueries extends LuceneTestCase {
   }
 
   public void testPointInSetEquals() {
-    Query q1 = IntPoint.newSetQuery("a", 0, 1000, 17);
-    Query q2 = IntPoint.newSetQuery("a", 17, 0, 1000);
+    Query q1, q2;
+    q1 = IntPoint.newSetQuery("a", 0, 1000, 17);
+    q2 = IntPoint.newSetQuery("a", 17, 0, 1000);
     assertEquals(q1, q2);
     assertEquals(q1.hashCode(), q2.hashCode());
     assertFalse(q1.equals(IntPoint.newSetQuery("a", 1, 17, 1000)));
+    assertFalse(q1.equals(IntPoint.newSetQuery("b", 0, 1000, 17)));
 
     q1 = LongPoint.newSetQuery("a", 0, 1000, 17);
     q2 = LongPoint.newSetQuery("a", 17, 0, 1000);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestPointQueryParser.java
----------------------------------------------------------------------
diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestPointQueryParser.java
b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestPointQueryParser.java
index 323b0ff..a301de0 100644
--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestPointQueryParser.java
+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestPointQueryParser.java
@@ -75,7 +75,7 @@ public class TestPointQueryParser extends LuceneTestCase {
     
     assertEquals(DoublePoint.newRangeQuery("doubleField", 1.5D, 3.6D),
                  parser.parse("doubleField:[1.5 TO 3.6]", "body"));
-    assertEquals(DoublePoint.newRangeQuery("floatField", 1.5D, 1.5D),
+    assertEquals(DoublePoint.newRangeQuery("doubleField", 1.5D, 1.5D),
                  parser.parse("doubleField:1.5", "body"));
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
index bba92b3..10d11c6 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
@@ -295,7 +295,7 @@ final class LatLonPointDistanceQuery extends Query {
     if (!super.equals(obj)) return false;
     if (getClass() != obj.getClass()) return false;
     LatLonPointDistanceQuery other = (LatLonPointDistanceQuery) obj;
-    if (!field.equals(other.field)) return false;
+    if (field.equals(other.field) == false) return false;
     if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude)) return
false;
     if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude)) return
false;
     if (Double.doubleToLongBits(radiusMeters) != Double.doubleToLongBits(other.radiusMeters))
return false;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
index 68c734e..494f427 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
@@ -258,6 +258,9 @@ final class LatLonPointInPolygonQuery extends Query {
 
     LatLonPointInPolygonQuery that = (LatLonPointInPolygonQuery) o;
 
+    if (field.equals(that.field) == false) {
+      return false;
+    }
     if (Arrays.equals(polyLons, that.polyLons) == false) {
       return false;
     }
@@ -269,8 +272,9 @@ final class LatLonPointInPolygonQuery extends Query {
   }
 
   @Override
-  public final int hashCode() {
+  public int hashCode() {
     int result = super.hashCode();
+    result = 31 * result + field.hashCode();
     result = 31 * result + Arrays.hashCode(polyLons);
     result = 31 * result + Arrays.hashCode(polyLats);
     return result;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/sandbox/src/test/org/apache/lucene/document/TestBigIntegerPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestBigIntegerPoint.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestBigIntegerPoint.java
index 7d9281b..98c6a67 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestBigIntegerPoint.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestBigIntegerPoint.java
@@ -96,11 +96,13 @@ public class TestBigIntegerPoint extends LuceneTestCase {
   }
 
   public void testQueryEquals() throws Exception {
-    Query q1 = BigIntegerPoint.newRangeQuery("a", BigInteger.valueOf(0), BigInteger.valueOf(1000));
-    Query q2 = BigIntegerPoint.newRangeQuery("a", BigInteger.valueOf(0), BigInteger.valueOf(1000));
+    Query q1, q2;
+    q1 = BigIntegerPoint.newRangeQuery("a", BigInteger.valueOf(0), BigInteger.valueOf(1000));
+    q2 = BigIntegerPoint.newRangeQuery("a", BigInteger.valueOf(0), BigInteger.valueOf(1000));
     assertEquals(q1, q2);
     assertEquals(q1.hashCode(), q2.hashCode());
     assertFalse(q1.equals(BigIntegerPoint.newRangeQuery("a", BigInteger.valueOf(1), BigInteger.valueOf(1000))));
+    assertFalse(q1.equals(BigIntegerPoint.newRangeQuery("b", BigInteger.valueOf(0), BigInteger.valueOf(1000))));
 
     q1 = BigIntegerPoint.newExactQuery("a", BigInteger.valueOf(1000));
     q2 = BigIntegerPoint.newExactQuery("a", BigInteger.valueOf(1000));

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
b/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
index ee34ecc..673ee29 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
@@ -92,11 +92,13 @@ public class TestInetAddressPoint extends LuceneTestCase {
   }
 
   public void testQueryEquals() throws Exception {
-    Query q1 = InetAddressPoint.newRangeQuery("a", InetAddress.getByName("1.2.3.3"), InetAddress.getByName("1.2.3.5"));
-    Query q2 = InetAddressPoint.newRangeQuery("a", InetAddress.getByName("1.2.3.3"), InetAddress.getByName("1.2.3.5"));
+    Query q1, q2;
+    q1 = InetAddressPoint.newRangeQuery("a", InetAddress.getByName("1.2.3.3"), InetAddress.getByName("1.2.3.5"));
+    q2 = InetAddressPoint.newRangeQuery("a", InetAddress.getByName("1.2.3.3"), InetAddress.getByName("1.2.3.5"));
     assertEquals(q1, q2);
     assertEquals(q1.hashCode(), q2.hashCode());
     assertFalse(q1.equals(InetAddressPoint.newRangeQuery("a", InetAddress.getByName("1.2.3.3"),
InetAddress.getByName("1.2.3.7"))));
+    assertFalse(q1.equals(InetAddressPoint.newRangeQuery("b", InetAddress.getByName("1.2.3.3"),
InetAddress.getByName("1.2.3.5"))));
 
     q1 = InetAddressPoint.newPrefixQuery("a", InetAddress.getByName("1.2.3.3"), 16);
     q2 = InetAddressPoint.newPrefixQuery("a", InetAddress.getByName("1.2.3.3"), 16);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
index 71ef7ef..b136776 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
@@ -45,7 +45,7 @@ public class TestLatLonPointQueries extends BaseGeoPointTestCase {
 
   @Override
   protected Query newPolygonQuery(String field, double[] lats, double[] lons) {
-    return LatLonPoint.newPolygonQuery(FIELD_NAME, lats, lons);
+    return LatLonPoint.newPolygonQuery(field, lats, lons);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
index 0efe7d61..3943a92 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
@@ -971,4 +971,47 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
     writer.close();
     dir.close();
   }
+
+  public void testEquals() throws Exception {   
+    Query q1, q2;
+
+    GeoRect rect = randomRect(false, true);
+
+    q1 = newRectQuery("field", rect);
+    q2 = newRectQuery("field", rect);
+    assertEquals(q1, q2);
+    assertFalse(q1.equals(newRectQuery("field2", rect)));
+
+    double lat = randomLat(false);
+    double lon = randomLon(false);
+    q1 = newDistanceQuery("field", lat, lon, 10000.0);
+    q2 = newDistanceQuery("field", lat, lon, 10000.0);
+    assertEquals(q1, q2);
+    assertFalse(q1.equals(newDistanceQuery("field2", lat, lon, 10000.0)));
+
+    q1 = newDistanceRangeQuery("field", lat, lon, 10000.0, 100000.0);
+    if (q1 != null) {
+      // Not all subclasses can make distance range query!
+      q2 = newDistanceRangeQuery("field", lat, lon, 10000.0, 100000.0);
+      assertEquals(q1, q2);
+      assertFalse(q1.equals(newDistanceRangeQuery("field2", lat, lon, 10000.0, 100000.0)));
+    }
+
+    double[] lats = new double[5];
+    double[] lons = new double[5];
+    lats[0] = rect.minLat;
+    lons[0] = rect.minLon;
+    lats[1] = rect.maxLat;
+    lons[1] = rect.minLon;
+    lats[2] = rect.maxLat;
+    lons[2] = rect.maxLon;
+    lats[3] = rect.minLat;
+    lons[3] = rect.maxLon;
+    lats[4] = rect.minLat;
+    lons[4] = rect.minLon;
+    q1 = newPolygonQuery("field", lats, lons);
+    q2 = newPolygonQuery("field", lats, lons);
+    assertEquals(q1, q2);
+    assertFalse(q1.equals(newPolygonQuery("field2", lats, lons)));
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java
b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java
index c9b5e4e..3cc9530 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java
@@ -187,6 +187,9 @@ final class PointInGeo3DShapeQuery extends Query {
     if (!super.equals(o)) return false;
 
     PointInGeo3DShapeQuery that = (PointInGeo3DShapeQuery) o;
+    if (field.equals(that.field) == false) {
+      return false;
+    }
 
     return shape.equals(that.shape);
   }
@@ -194,6 +197,7 @@ final class PointInGeo3DShapeQuery extends Query {
   @Override
   public int hashCode() {
     int result = super.hashCode();
+    result = 31 * result + field.hashCode();
     result = 31 * result + shape.hashCode();
     return result;
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/064f599c/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
index 3061b76..5c0044f 100644
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
@@ -812,6 +812,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
     GeoShape shape = randomShape(PlanetModel.WGS84);
     Query q = Geo3DPoint.newShapeQuery("point", shape);
     assertEquals(q, Geo3DPoint.newShapeQuery("point", shape));
+    assertFalse(q.equals(Geo3DPoint.newShapeQuery("point2", shape)));
     
     // make a different random shape:
     GeoShape shape2;


Mime
View raw message