lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [18/26] lucene-solr:jira/solr-12730: Minor LatLonShape cleanup
Date Mon, 05 Nov 2018 18:56:36 GMT
Minor LatLonShape cleanup

Reinstate TestLatLonPointShapeQueries.testRandomTiny, remove unused
area calculation of Tessellated triangles. Javadoc cleanup.


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

Branch: refs/heads/jira/solr-12730
Commit: 2b8f577c229c3158b530056073bc591c8509a7f9
Parents: bbb9f72
Author: Nicholas Knize <nknize@gmail.com>
Authored: Fri Nov 2 11:06:22 2018 -0500
Committer: Nicholas Knize <nknize@gmail.com>
Committed: Fri Nov 2 11:06:22 2018 -0500

----------------------------------------------------------------------
 .../org/apache/lucene/document/LatLonShape.java | 15 ++++++++++-----
 .../document/BaseLatLonShapeTestCase.java       | 20 ++++++++++++++++++--
 .../document/TestLatLonPointShapeQueries.java   |  4 ----
 3 files changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2b8f577c/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShape.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShape.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShape.java
index 1d17b10..99d7c08 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShape.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShape.java
@@ -84,7 +84,6 @@ public class LatLonShape {
 
     // create "flat" triangles
     double aLat, bLat, aLon, bLon, temp;
-    double size;
     for (int i = 0, j = 1; j < numPoints; ++i, ++j) {
       aLat = line.getLat(i);
       aLon = line.getLon(i);
@@ -107,15 +106,14 @@ public class LatLonShape {
           bLon = temp;
         }
       }
-      size = StrictMath.sqrt(StrictMath.pow(aLat - bLat, 2d) + StrictMath.pow(aLon - bLon,
2d));
-      fields.add(new LatLonTriangle(fieldName, aLat, aLon, bLat, bLon, aLat, aLon, size));
+      fields.add(new LatLonTriangle(fieldName, aLat, aLon, bLat, bLon, aLat, aLon));
     }
     return fields.toArray(new Field[fields.size()]);
   }
 
   /** create indexable fields for point geometry */
   public static Field[] createIndexableFields(String fieldName, double lat, double lon) {
-    return new Field[] {new LatLonTriangle(fieldName, lat, lon, lat, lon, lat, lon, 0d)};
+    return new Field[] {new LatLonTriangle(fieldName, lat, lon, lat, lon, lat, lon)};
   }
 
   /** create a query to find all polygons that intersect a defined bounding box
@@ -126,6 +124,9 @@ public class LatLonShape {
     return new LatLonShapeBoundingBoxQuery(field, queryRelation, minLatitude, maxLatitude,
minLongitude, maxLongitude);
   }
 
+  /** create a query to find all polygons that intersect a provided polygon (or array of
polygons)
+   *  note: does not support dateline crossing
+   **/
   public static Query newPolygonQuery(String field, QueryRelation queryRelation, Polygon...
polygons) {
     return new LatLonShapePolygonQuery(field, queryRelation, polygons);
   }
@@ -135,7 +136,7 @@ public class LatLonShape {
    */
   private static class LatLonTriangle extends Field {
 
-    LatLonTriangle(String name, double aLat, double aLon, double bLat, double bLon, double
cLat, double cLon, double size) {
+    LatLonTriangle(String name, double aLat, double aLon, double bLat, double bLon, double
cLat, double cLon) {
       super(name, TYPE);
       setTriangleValue(encodeLongitude(aLon), encodeLatitude(aLat), encodeLongitude(bLon),
encodeLatitude(bLat), encodeLongitude(cLon), encodeLatitude(cLat));
     }
@@ -178,6 +179,9 @@ public class LatLonShape {
     }
   }
 
+  /** encodes bounding box value of triangle. Note the encoding uses 64bit encoding, but
the bounding box only needs
+   * 32bits, so we pad w/ zeros to take advantage of prefix compression.
+   */
   public static void encodeTriangleBoxVal(int encodedVal, byte[] bytes, int offset) {
     long val = (long)(encodedVal ^ 0x80000000);
     val &= 0x00000000FFFFFFFFL;
@@ -185,6 +189,7 @@ public class LatLonShape {
     NumericUtils.longToSortableBytes(val, bytes, offset);
   }
 
+  /** counterpart to {@link #encodeTriangleBoxVal}; decodes encoded triangle bounding box
values */
   public static int decodeTriangleBoxVal(byte[] encoded, int offset) {
     long val = NumericUtils.sortableBytesToLong(encoded, offset);
     int result = (int)(val & 0x00000000FFFFFFFF);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2b8f577c/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
b/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
index 9c9462f..35f980d 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
@@ -59,8 +59,11 @@ import static org.apache.lucene.geo.GeoEncodingUtils.encodeLongitudeCeil;
 import static org.apache.lucene.geo.GeoTestUtil.nextLatitude;
 import static org.apache.lucene.geo.GeoTestUtil.nextLongitude;
 
+/** base test class for {@link TestLatLonLineShapeQueries}, {@link TestLatLonPointShapeQueries},
+ * and {@link TestLatLonPolygonShapeQueries} */
 public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
 
+  /** name of the LatLonShape indexed field */
   protected static final String FIELD_NAME = "shape";
 
   protected abstract ShapeType getShapeType();
@@ -69,22 +72,27 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
     return getShapeType().nextShape();
   }
 
+  /** quantizes a latitude value to be consistent with index encoding */
   protected double quantizeLat(double rawLat) {
     return decodeLatitude(encodeLatitude(rawLat));
   }
 
+  /** quantizes a provided latitude value rounded up to the nearest encoded integer */
   protected double quantizeLatCeil(double rawLat) {
     return decodeLatitude(encodeLatitudeCeil(rawLat));
   }
 
+  /** quantizes a longitude value to be consistent with index encoding */
   protected double quantizeLon(double rawLon) {
     return decodeLongitude(encodeLongitude(rawLon));
   }
 
+  /** quantizes a provided longitude value rounded up to the nearest encoded integer */
   protected double quantizeLonCeil(double rawLon) {
     return decodeLongitude(encodeLongitudeCeil(rawLon));
   }
 
+  /** quantizes a provided polygon to be consistent with the index encoding */
   protected Polygon quantizePolygon(Polygon polygon) {
     double[] lats = new double[polygon.numPoints()];
     double[] lons = new double[polygon.numPoints()];
@@ -95,6 +103,7 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
     return new Polygon(lats, lons);
   }
 
+  /** quantizes a provided linestring to be consistent with the index encoding */
   protected Line quantizeLine(Line line) {
     double[] lats = new double[line.numPoints()];
     double[] lons = new double[line.numPoints()];
@@ -105,8 +114,10 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase
{
     return new Line(lats, lons);
   }
 
+  /** creates the array of LatLonShape.Triangle values that are used to index the shape */
   protected abstract Field[] createIndexableFields(String field, Object shape);
 
+  /** adds a shape to a provided document */
   private void addShapeToDoc(String field, Document doc, Object shape) {
     Field[] fields = createIndexableFields(field, shape);
     for (Field f : fields) {
@@ -114,10 +125,12 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase
{
     }
   }
 
+  /** factory method to create a new bounding box query */
   protected Query newRectQuery(String field, QueryRelation queryRelation, double minLat,
double maxLat, double minLon, double maxLon) {
     return LatLonShape.newBoxQuery(field, queryRelation, minLat, maxLat, minLon, maxLon);
   }
 
+  /** factory method to create a new polygon query */
   protected Query newPolygonQuery(String field, QueryRelation queryRelation, Polygon... polygons)
{
     return LatLonShape.newPolygonQuery(field, queryRelation, polygons);
   }
@@ -212,8 +225,8 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
         addShapeToDoc(FIELD_NAME, doc, shapes[id]);
       }
       w.addDocument(doc);
-      if (id > 0 && randomInt(100) == 42) {
-        int idToDelete = randomInt(id);
+      if (id > 0 && random().nextInt(100) == 42) {
+        int idToDelete = random().nextInt(id);
         w.deleteDocuments(new Term("id", ""+idToDelete));
         deleted.add(idToDelete);
         if (VERBOSE) {
@@ -227,6 +240,7 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
     }
   }
 
+  /** test random generated bounding boxes */
   protected void verifyRandomBBoxQueries(IndexReader reader, Object... shapes) throws Exception
{
     IndexSearcher s = newSearcher(reader);
 
@@ -323,6 +337,7 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
     }
   }
 
+  /** test random generated polygons */
   protected void verifyRandomPolygonQueries(IndexReader reader, Object... shapes) throws
Exception {
     IndexSearcher s = newSearcher(reader);
 
@@ -481,6 +496,7 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
     }
   }
 
+  /** validator class used to test query results against "ground truth" */
   protected abstract class Validator {
     protected QueryRelation queryRelation = QueryRelation.INTERSECTS;
     public abstract boolean testBBoxQuery(double minLat, double maxLat, double minLon, double
maxLon, Object shape);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2b8f577c/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
index df924fe..00bb8d4 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
@@ -75,8 +75,4 @@ public class TestLatLonPointShapeQueries extends BaseLatLonShapeTestCase
{
       return r != Relation.CELL_OUTSIDE_QUERY;
     }
   }
-
-  @Override
-  public void testRandomTiny() throws Exception {
-  }
 }


Mime
View raw message