lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkn...@apache.org
Subject svn commit: r1709892 - in /lucene/dev/branches/lucene6780/lucene/sandbox/src: java/org/apache/lucene/util/ test/org/apache/lucene/search/ test/org/apache/lucene/util/
Date Wed, 21 Oct 2015 17:32:27 GMT
Author: nknize
Date: Wed Oct 21 17:32:27 2015
New Revision: 1709892

URL: http://svn.apache.org/viewvc?rev=1709892&view=rev
Log:
LUCENE-6780: fix quantization in random lat/lon generation, cut overly adversarial tests to
@Nightly


Modified:
    lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
    lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
    lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
    lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java

Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java?rev=1709892&r1=1709891&r2=1709892&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
(original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
Wed Oct 21 17:32:27 2015
@@ -76,7 +76,7 @@ public final class GeoUtils {
 
   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;
   }
 
   /**

Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java?rev=1709892&r1=1709891&r2=1709892&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
(original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
Wed Oct 21 17:32:27 2015
@@ -143,11 +143,6 @@ public class TestGeoPointQuery extends B
 
   @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 ||

Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java?rev=1709892&r1=1709891&r2=1709892&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
(original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
Wed Oct 21 17:32:27 2015
@@ -19,10 +19,12 @@ package org.apache.lucene.util;
 
 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 @@ public abstract class BaseGeoPointTestCa
 
   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 @@ public abstract class BaseGeoPointTestCa
   }
 
   // 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 @@ public abstract class BaseGeoPointTestCa
     verify(small, lats, lons);
   }
 
+  @Nightly
   public void testMultiValued() throws Exception {
     int numPoints = atLeast(10000);
     // Every doc has 2 points:
@@ -201,8 +208,8 @@ public abstract class BaseGeoPointTestCa
     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 @@ public abstract class BaseGeoPointTestCa
 
     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 @@ public abstract class BaseGeoPointTestCa
     verify(small, lats, lons);
   }
 
-  protected static double randomLat(boolean small) {
+  public static long scaleLon(final double val) {
+    return (long) ((val-GeoUtils.MIN_LON_INCL) * LON_SCALE);
+  }
+
+  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.normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
+      result = GeoUtils.normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
     } else {
-      return -90 + 180.0 * random().nextDouble();
+      result = -90 + 180.0 * random().nextDouble();
     }
+    return unscaleLat(scaleLat(result));
   }
 
-  protected static double randomLon(boolean small) {
+  public static double randomLon(boolean small) {
+    double result;
     if (small) {
-      return GeoUtils.normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
+      result = GeoUtils.normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
     } else {
-      return -180 + 360.0 * random().nextDouble();
+      result = -180 + 360.0 * random().nextDouble();
     }
+    return unscaleLon(scaleLon(result));
   }
 
   protected static GeoRect randomRect(boolean small, boolean canCrossDateLine) {
@@ -630,7 +656,8 @@ public abstract class BaseGeoPointTestCa
                 }
 
                 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 {

Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java?rev=1709892&r1=1709891&r2=1709892&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java
(original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java
Wed Oct 21 17:32:27 2015
@@ -67,8 +67,8 @@ public class TestGeoUtils extends Lucene
     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 @@ public class TestGeoUtils extends Lucene
     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 @@ public class TestGeoUtils extends Lucene
   }
 
   /** 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 @@ public class TestGeoUtils extends Lucene
     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 @@ public class TestGeoUtils extends Lucene
 
       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:
 



Mime
View raw message