mirror of https://github.com/apache/lucene.git
LUCENE-7133: check field name in equals/hashCode for point queries
This commit is contained in:
parent
dbee659174
commit
97b6270337
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue