LUCENE-6780: fix quantization in random lat/lon generation, cut overly adversarial tests to @Nightly
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene6780@1709892 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java b/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
index c2d46ae..1baa2a1 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
@@ -76,7 +76,7 @@
public static double compare(final double v1, final double v2) {
final double delta = v1-v2;
- return ((int)(Math.abs(delta)/TOLERANCE)*TOLERANCE) <= TOLERANCE ? 0 : delta;
+ return Math.abs(delta) <= TOLERANCE ? 0 : delta;
}
/**
diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
index 663ef53..637a210 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
@@ -143,11 +143,6 @@
@Override
protected Boolean rectContainsPoint(GeoRect rect, double pointLat, double pointLon) {
- // First quantize the point like the index does:
- long pointHash = GeoUtils.mortonHash(pointLon, pointLat);
- pointLon = GeoUtils.mortonUnhashLon(pointHash);
- pointLat = GeoUtils.mortonUnhashLat(pointHash);
-
if (GeoUtils.compare(pointLon, rect.minLon) == 0.0 ||
GeoUtils.compare(pointLon, rect.maxLon) == 0.0 ||
GeoUtils.compare(pointLat, rect.minLat) == 0.0 ||
diff --git a/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java b/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
index dd19464..87f98dd 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
@@ -19,10 +19,12 @@
import java.io.IOException;
import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -51,6 +53,9 @@
protected static final String FIELD_NAME = "point";
+ private static final double LON_SCALE = (0x1L<<GeoUtils.BITS)/360.0D;
+ private static final double LAT_SCALE = (0x1L<<GeoUtils.BITS)/180.0D;
+
private static double originLat;
private static double originLon;
private static double lonRange;
@@ -67,6 +72,7 @@
}
// A particularly tricky adversary for BKD tree:
+ @Nightly
public void testSamePointManyTimes() throws Exception {
int numPoints = atLeast(1000);
// TODO: GeoUtils are potentially slow if we use small=false with heavy testing
@@ -187,6 +193,7 @@
verify(small, lats, lons);
}
+ @Nightly
public void testMultiValued() throws Exception {
int numPoints = atLeast(10000);
// Every doc has 2 points:
@@ -201,8 +208,8 @@
RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc);
// TODO: GeoUtils are potentially slow if we use small=false with heavy testing
- // boolean small = random().nextBoolean();
- boolean small = true;
+ boolean small = random().nextBoolean();
+ //boolean small = true;
for (int id=0;id<numPoints;id++) {
Document doc = new Document();
@@ -233,7 +240,6 @@
int iters = atLeast(75);
for (int iter=0;iter<iters;iter++) {
- // Don't allow dateline crossing when testing small:
GeoRect rect = randomRect(small, small == false);
if (VERBOSE) {
@@ -393,20 +399,40 @@
verify(small, lats, lons);
}
- protected static double randomLat(boolean small) {
- if (small) {
- return GeoUtils.normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
- } else {
- return -90 + 180.0 * random().nextDouble();
- }
+ public static long scaleLon(final double val) {
+ return (long) ((val-GeoUtils.MIN_LON_INCL) * LON_SCALE);
}
- protected static double randomLon(boolean small) {
+ public static long scaleLat(final double val) {
+ return (long) ((val-GeoUtils.MIN_LAT_INCL) * LAT_SCALE);
+ }
+
+ public static double unscaleLon(final long val) {
+ return (val / LON_SCALE) + GeoUtils.MIN_LON_INCL;
+ }
+
+ public static double unscaleLat(final long val) {
+ return (val / LAT_SCALE) + GeoUtils.MIN_LAT_INCL;
+ }
+
+ public static double randomLat(boolean small) {
+ double result;
if (small) {
- return GeoUtils.normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
+ result = GeoUtils.normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
} else {
- return -180 + 360.0 * random().nextDouble();
+ result = -90 + 180.0 * random().nextDouble();
}
+ return unscaleLat(scaleLat(result));
+ }
+
+ public static double randomLon(boolean small) {
+ double result;
+ if (small) {
+ result = GeoUtils.normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
+ } else {
+ result = -180 + 360.0 * random().nextDouble();
+ }
+ return unscaleLon(scaleLon(result));
}
protected static GeoRect randomRect(boolean small, boolean canCrossDateLine) {
@@ -630,7 +656,8 @@
}
if (VERBOSE) {
- System.out.println(" radiusMeters = " + new DecimalFormat("#,###.00").format(radiusMeters));
+ final DecimalFormat df = new DecimalFormat("#,###.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
+ System.out.println(" radiusMeters = " + df.format(radiusMeters));
}
try {
diff --git a/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java b/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java
index 1e2d266..058df8a 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java
@@ -67,8 +67,8 @@
int randomLevel;
for (int i = 0; i < numPoints; ++i) {
// random point
- double lat = randomLat(false);
- double lon = randomLon(false);
+ double lat = BaseGeoPointTestCase.randomLat(false);
+ double lon = BaseGeoPointTestCase.randomLon(false);
// compute geohash straight from lat/lon and from morton encoded value to ensure they're the same
randomGeoHashString = GeoHashUtils.stringEncode(lon, lat, randomLevel = random().nextInt(12 - 1) + 1);
@@ -211,22 +211,6 @@
assertEquals(0.0, result[1], 0.0);
}
- public static double randomLon(boolean useSmallRanges) {
- if (useSmallRanges) {
- return GeoUtils.normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
- } else {
- return (360d * random().nextDouble()) - 180d;
- }
- }
-
- public static double randomLat(boolean useSmallRanges) {
- if (useSmallRanges) {
- return GeoUtils.normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
- } else {
- return (180d * random().nextDouble()) - 90d;
- }
- }
-
private static class Cell {
static int nextCellID;
@@ -392,7 +376,6 @@
}
/** Tests consistency of GeoUtils.rectWithinCircle, .rectCrossesCircle, .rectWithin and SloppyMath.haversine distance check */
- @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/LUCENE-6846")
public void testGeoRelations() throws Exception {
int numDocs = atLeast(1000);
@@ -409,8 +392,8 @@
double[] docLons = new double[numDocs];
double[] docLats = new double[numDocs];
for(int docID=0;docID<numDocs;docID++) {
- docLons[docID] = randomLon(useSmallRanges);
- docLats[docID] = randomLat(useSmallRanges);
+ docLons[docID] = BaseGeoPointTestCase.randomLon(useSmallRanges);
+ docLats[docID] = BaseGeoPointTestCase.randomLat(useSmallRanges);
if (VERBOSE) {
System.out.println(" doc=" + docID + ": lon=" + docLons[docID] + " lat=" + docLats[docID]);
}
@@ -424,8 +407,8 @@
Cell.nextCellID = 0;
- double centerLon = randomLon(useSmallRanges);
- double centerLat = randomLat(useSmallRanges);
+ double centerLon = BaseGeoPointTestCase.randomLon(useSmallRanges);
+ double centerLat = BaseGeoPointTestCase.randomLat(useSmallRanges);
// So the circle covers at most 50% of the earth's surface: