Apache Lucene open-source search software
LUCENE-4444 Use SpatialContext to read shape strings. Necessary for supporting 3rd party spatial contexts such as the JTS one to use polygons.
David Wayne Smiley6f6884e4ed71
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.java b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.javaindex 61fd0e5e0fb..2783af382bd 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.java@@ -86,7 +86,7 @@ public class SpatialArgsParser {throw new IllegalArgumentException("missing body : " + v, null);}- Shape shape = new ShapeReadWriter(ctx).readShape(body);+ Shape shape = ctx.readShape(body);SpatialArgs args = new SpatialArgs(op, shape);if (v.length() > (edx + 1)) {diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java b/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.javaindex ea63b87cc21..2a5b00b97de 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java@@ -21,7 +21,6 @@ import com.carrotsearch.randomizedtesting.annotations.Name;import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.distance.DistanceUtils;-import com.spatial4j.core.io.ShapeReadWriter;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Shape;import org.apache.lucene.search.FilteredQuery;@@ -162,7 +161,7 @@ public class PortedSolr3Test extends StrategyTestCase {private void _checkHits(boolean bbox, String ptStr, double distKM, int assertNumFound, int... assertIds) {SpatialOperation op = SpatialOperation.Intersects;- Point pt = (Point) new ShapeReadWriter(ctx).readShape(ptStr);+ Point pt = (Point) ctx.readShape(ptStr);double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);Shape shape = ctx.makeCircle(pt, distDEG);if (bbox)diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.javaindex 7b517480904..5c24f18a782 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java@@ -19,7 +19,6 @@ package org.apache.lucene.spatial;import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.distance.DistanceUtils;-import com.spatial4j.core.io.ShapeReadWriter;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Shape;import org.apache.lucene.document.Document;@@ -111,7 +110,7 @@ public class SpatialExample extends LuceneTestCase {//When parsing a string to a shape, the presence of a comma means it's y-x// order (lon, lat)indexWriter.addDocument(newSampleDocument(- 4, new ShapeReadWriter(ctx).readShape("-50.7693246, 60.9289094")));+ 4, ctx.readShape("-50.7693246, 60.9289094")));indexWriter.addDocument(newSampleDocument(20, ctx.makePoint(0.1,0.1), ctx.makePoint(0, 0)));diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.javaindex fea9913c97e..28459025157 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java@@ -19,7 +19,6 @@ package org.apache.lucene.spatial;*/import com.spatial4j.core.context.SpatialContext;-import com.spatial4j.core.io.ShapeReadWriter;import com.spatial4j.core.io.sample.SampleData;import com.spatial4j.core.io.sample.SampleDataReader;import com.spatial4j.core.shape.Shape;@@ -89,7 +88,7 @@ public abstract class StrategyTestCase extends SpatialTestCase {Document document = new Document();document.add(new StringField("id", data.id, Field.Store.YES));document.add(new StringField("name", data.name, Field.Store.YES));- Shape shape = new ShapeReadWriter(ctx).readShape(data.shape);+ Shape shape = ctx.readShape(data.shape);shape = convertShapeFromGetDocuments(shape);if (shape != null) {for (Field f : strategy.createIndexableFields(shape)) {@@ -130,7 +129,7 @@ public abstract class StrategyTestCase extends SpatialTestCase {SearchResults got = executeQuery(strategy.makeQuery(q.args), 100);if (storeShape && got.numFound > 0) {//check stored value is there & parses- assertNotNull(new ShapeReadWriter(ctx).readShape(got.results.get(0).document.get(strategy.getFieldName())));+ assertNotNull(ctx.readShape(got.results.get(0).document.get(strategy.getFieldName())));}if (concern.orderIsImportant) {Iterator<String> ids = q.ids.iterator();@@ -174,7 +173,7 @@ public abstract class StrategyTestCase extends SpatialTestCase {}protected void adoc(String id, String shapeStr) throws IOException {- Shape shape = shapeStr==null ? null : new ShapeReadWriter(ctx).readShape(shapeStr);+ Shape shape = shapeStr==null ? null : ctx.readShape(shapeStr);addDocument(newDoc(id, shape));}protected void adoc(String id, Shape shape) throws IOException {