Apache Lucene open-source search software
LUCENE-4167 migrate com.spatial4j.core.query to Lucene spatial. migrate UnsupportedSpatialOperation too.
David Wayne Smiley9349890f2869
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.javaindex 078eda627cd..6fb471f9155 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,10 +17,7 @@* limitations under the License.*/-package org.apache.lucene.spatial;-import com.spatial4j.core.context.SpatialContext;-import com.spatial4j.core.query.SpatialArgs;import com.spatial4j.core.shape.Shape;import org.apache.lucene.index.IndexableField;import org.apache.lucene.queries.function.FunctionQuery;@@ -26,6 +25,7 @@ import org.apache.lucene.queries.function.ValueSource;import org.apache.lucene.search.Filter;import org.apache.lucene.search.FilteredQuery;import org.apache.lucene.search.Query;+import org.apache.lucene.spatial.query.SpatialArgs;/*** must be thread safe@@ -72,8 +72,8 @@ public abstract class SpatialStrategy<T extends SpatialFieldInfo> {/*** Make a query which has a score based on the distance from the data to the query shape.* The default implementation constructs a {@link FilteredQuery} based on- * {@link #makeFilter(com.spatial4j.core.query.SpatialArgs, SpatialFieldInfo)} and- * {@link #makeValueSource(com.spatial4j.core.query.SpatialArgs, SpatialFieldInfo)}.+ * {@link #makeFilter(org.apache.lucene.spatial.query.SpatialArgs, SpatialFieldInfo)} and+ * {@link #makeValueSource(org.apache.lucene.spatial.query.SpatialArgs, SpatialFieldInfo)}.*/public Query makeQuery(SpatialArgs args, T fieldInfo) {Filter filter = makeFilter(args, fieldInfo);diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.javaindex 97f5a4743c0..9aa22d51eb1 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.bbox;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -14,11 +16,10 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.lucene.spatial.bbox;--import java.text.NumberFormat;-import java.util.Locale;+import com.spatial4j.core.context.SpatialContext;+import com.spatial4j.core.shape.Rectangle;+import com.spatial4j.core.shape.Shape;import org.apache.lucene.document.Field;import org.apache.lucene.document.FieldType;import org.apache.lucene.index.FieldInfo.IndexOptions;@@ -26,21 +27,15 @@ import org.apache.lucene.index.IndexableField;import org.apache.lucene.index.Term;import org.apache.lucene.queries.function.FunctionQuery;import org.apache.lucene.queries.function.ValueSource;-import org.apache.lucene.search.BooleanClause;-import org.apache.lucene.search.BooleanQuery;-import org.apache.lucene.search.ConstantScoreQuery;-import org.apache.lucene.search.Filter;-import org.apache.lucene.search.NumericRangeQuery;-import org.apache.lucene.search.Query;-import org.apache.lucene.search.QueryWrapperFilter;-import org.apache.lucene.search.TermQuery;+import org.apache.lucene.search.*;import org.apache.lucene.spatial.SpatialStrategy;+import org.apache.lucene.spatial.query.SpatialArgs;+import org.apache.lucene.spatial.query.SpatialOperation;+import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;import org.apache.lucene.spatial.util.NumericFieldInfo;-import com.spatial4j.core.context.*;-import com.spatial4j.core.exception.UnsupportedSpatialOperation;-import com.spatial4j.core.query.*;-import com.spatial4j.core.shape.*;+import java.text.NumberFormat;+import java.util.Locale;/**diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.javaindex d390ff3ea1a..4808cdfefe2 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.prefix;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,10 +17,7 @@* limitations under the License.*/-package org.apache.lucene.spatial.prefix;-import com.spatial4j.core.distance.DistanceCalculator;-import com.spatial4j.core.query.SpatialArgs;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Shape;import org.apache.lucene.analysis.TokenStream;@@ -32,6 +31,7 @@ import org.apache.lucene.spatial.SimpleSpatialFieldInfo;import org.apache.lucene.spatial.SpatialStrategy;import org.apache.lucene.spatial.prefix.tree.Node;import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;+import org.apache.lucene.spatial.query.SpatialArgs;import org.apache.lucene.spatial.util.CachedDistanceValueSource;import java.util.Iterator;diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.javaindex e7636735e8e..0a91949ba49 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.prefix;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,15 +17,13 @@* limitations under the License.*/-package org.apache.lucene.spatial.prefix;--import com.spatial4j.core.exception.UnsupportedSpatialOperation;-import com.spatial4j.core.query.SpatialArgs;-import com.spatial4j.core.query.SpatialOperation;import com.spatial4j.core.shape.Shape;import org.apache.lucene.search.Filter;import org.apache.lucene.spatial.SimpleSpatialFieldInfo;import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;+import org.apache.lucene.spatial.query.SpatialArgs;+import org.apache.lucene.spatial.query.SpatialOperation;+import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;/*** Based on {@link RecursivePrefixTreeFilter}.diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.javaindex f7e54b44201..03ac07758e4 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.prefix;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,11 +17,6 @@* limitations under the License.*/-package org.apache.lucene.spatial.prefix;--import com.spatial4j.core.exception.UnsupportedSpatialOperation;-import com.spatial4j.core.query.SpatialArgs;-import com.spatial4j.core.query.SpatialOperation;import com.spatial4j.core.shape.Shape;import org.apache.lucene.index.Term;import org.apache.lucene.queries.TermsFilter;@@ -27,6 +24,9 @@ import org.apache.lucene.search.Filter;import org.apache.lucene.spatial.SimpleSpatialFieldInfo;import org.apache.lucene.spatial.prefix.tree.Node;import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;+import org.apache.lucene.spatial.query.SpatialArgs;+import org.apache.lucene.spatial.query.SpatialOperation;+import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;import java.util.List;diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTree.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTree.javaindex 20c23faa6dc..e7b6bf70d0c 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTree.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTree.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.prefix.tree;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,8 +17,6 @@* limitations under the License.*/-package org.apache.lucene.spatial.prefix.tree;-import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Shape;@@ -63,7 +63,7 @@ public abstract class SpatialPrefixTree {}/**- * See {@link com.spatial4j.core.query.SpatialArgs#getDistPrecision()}.+ * See {@link org.apache.lucene.spatial.query.SpatialArgs#getDistPrecision()}.* A grid level looked up via {@link #getLevelForDistance(double)} is returned.** @param precision 0-0.5diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.javanew file mode 100644index 00000000000..e81a9f66d34--- /dev/null+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java@@ -0,0 +1,135 @@+package org.apache.lucene.spatial.query;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import com.spatial4j.core.context.SpatialContext;+import com.spatial4j.core.context.simple.SimpleSpatialContext;+import com.spatial4j.core.exception.InvalidSpatialArgument;+import com.spatial4j.core.shape.Shape;++/**+ * @lucene.experimental+ */+public class SpatialArgs {++ public static final double DEFAULT_DIST_PRECISION = 0.025d;++ private SpatialOperation operation;+ private Shape shape;+ private double distPrecision = DEFAULT_DIST_PRECISION;++ // Useful for 'distance' calculations+ private Double min;+ private Double max;++ public SpatialArgs(SpatialOperation operation) {+ this.operation = operation;+ }++ public SpatialArgs(SpatialOperation operation, Shape shape) {+ this.operation = operation;+ this.shape = shape;+ }++ /**+ * Check if the arguments make sense -- throw an exception if not+ */+ public void validate() throws InvalidSpatialArgument {+ if (operation.isTargetNeedsArea() && !shape.hasArea()) {+ throw new InvalidSpatialArgument(operation + " only supports geometry with area");+ }+ }++ public String toString( SpatialContext context ) {+ StringBuilder str = new StringBuilder();+ str.append( operation.getName() ).append( '(' );+ str.append( context.toString( shape ) );+ if( min != null ) {+ str.append(" min=").append(min);+ }+ if( max != null ) {+ str.append(" max=").append(max);+ }+ str.append(" distPrec=").append(String.format("%.2f%%", distPrecision/100d));+ str.append( ')' );+ return str.toString();+ }++ @Override+ public String toString()+ {+ return toString( SimpleSpatialContext.GEO_KM );+ }++ //------------------------------------------------+ // Getters & Setters+ //------------------------------------------------++ public SpatialOperation getOperation() {+ return operation;+ }++ public void setOperation(SpatialOperation operation) {+ this.operation = operation;+ }++ /**+ * Considers {@link SpatialOperation#BBoxWithin} in returning the shape.+ */+ public Shape getShape() {+ if (shape != null && (operation == SpatialOperation.BBoxWithin || operation == SpatialOperation.BBoxIntersects))+ return shape.getBoundingBox();+ return shape;+ }++ public void setShape(Shape shape) {+ this.shape = shape;+ }++ /**+ * The fraction of the distance from the center of the query shape to its nearest edge that is considered acceptable+ * error. The algorithm for computing the distance to the nearest edge is actually a little different. It normalizes+ * the shape to a square given it's bounding box area:+ * <pre>sqrt(shape.bbox.area)/2</pre>+ * And the error distance is beyond the shape such that the shape is a minimum shape.+ */+ public Double getDistPrecision() {+ return distPrecision;+ }++ public void setDistPrecision(Double distPrecision) {+ if (distPrecision != null)+ this.distPrecision = distPrecision;+ }++ public Double getMin() {+ return min;+ }++ public void setMin(Double min) {+ this.min = min;+ }++ public Double getMax() {+ return max;+ }++ public void setMax(Double max) {+ this.max = max;+ }+}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.javanew file mode 100644index 00000000000..fee494934ab--- /dev/null+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.java@@ -0,0 +1,91 @@+package org.apache.lucene.spatial.query;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import com.spatial4j.core.context.SpatialContext;+import com.spatial4j.core.exception.InvalidShapeException;+import com.spatial4j.core.exception.InvalidSpatialArgument;+import com.spatial4j.core.shape.Shape;++import java.util.HashMap;+import java.util.Map;+import java.util.StringTokenizer;++/**+ * @lucene.experimental+ */+public class SpatialArgsParser+{+ public SpatialArgs parse(String v, SpatialContext ctx) throws InvalidSpatialArgument, InvalidShapeException {+ int idx = v.indexOf('(');+ int edx = v.lastIndexOf(')');++ if (idx < 0 || idx > edx) {+ throw new InvalidSpatialArgument("missing parens: " + v, null);+ }++ SpatialOperation op = SpatialOperation.get(v.substring(0, idx).trim());++ String body = v.substring(idx + 1, edx).trim();+ if (body.length() < 1) {+ throw new InvalidSpatialArgument("missing body : " + v, null);+ }++ Shape shape = ctx.readShape(body);+ SpatialArgs args = new SpatialArgs(op,shape);++ if (v.length() > (edx + 1)) {+ body = v.substring( edx+1 ).trim();+ if (body.length() > 0) {+ Map<String,String> aa = parseMap(body);+ args.setMin(readDouble(aa.remove("min")) );+ args.setMax(readDouble(aa.remove("max")));+ args.setDistPrecision(readDouble(aa.remove("distPrec")));+ if (!aa.isEmpty()) {+ throw new InvalidSpatialArgument("unused parameters: " + aa, null);+ }+ }+ }+ return args;+ }++ protected static Double readDouble(String v) {+ return v == null ? null : Double.valueOf(v);+ }++ protected static boolean readBool(String v, boolean defaultValue) {+ return v == null ? defaultValue : Boolean.parseBoolean(v);+ }++ protected static Map<String,String> parseMap(String body) {+ Map<String,String> map = new HashMap<String,String>();+ StringTokenizer st = new StringTokenizer(body, " \n\t");+ while (st.hasMoreTokens()) {+ String a = st.nextToken();+ int idx = a.indexOf('=');+ if (idx > 0) {+ String k = a.substring(0, idx);+ String v = a.substring(idx + 1);+ map.put(k, v);+ } else {+ map.put(a, a);+ }+ }+ return map;+ }+}diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.javanew file mode 100644index 00000000000..4b2837d0836--- /dev/null+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java@@ -0,0 +1,108 @@+package org.apache.lucene.spatial.query;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import com.spatial4j.core.exception.InvalidSpatialArgument;++import java.io.Serializable;+import java.util.*;++/**+ * A clause that compares a stored geometry to a supplied geometry.+ *+ * @lucene.experimental+ */+public class SpatialOperation implements Serializable {+ // Private registry+ private static final Map<String, SpatialOperation> registry = new HashMap<String, SpatialOperation>();+ private static final List<SpatialOperation> list = new ArrayList<SpatialOperation>();++ // Geometry Operations+ public static final SpatialOperation BBoxIntersects = new SpatialOperation("BBoxIntersects", true, false, false);+ public static final SpatialOperation BBoxWithin = new SpatialOperation("BBoxWithin", true, false, false);+ public static final SpatialOperation Contains = new SpatialOperation("Contains", true, true, false);+ public static final SpatialOperation Intersects = new SpatialOperation("Intersects", true, false, false);+ public static final SpatialOperation IsEqualTo = new SpatialOperation("IsEqualTo", false, false, false);+ public static final SpatialOperation IsDisjointTo = new SpatialOperation("IsDisjointTo", false, false, false);+ public static final SpatialOperation IsWithin = new SpatialOperation("IsWithin", true, false, true);+ public static final SpatialOperation Overlaps = new SpatialOperation("Overlaps", true, false, true);++ // Member variables+ private final boolean scoreIsMeaningful;+ private final boolean sourceNeedsArea;+ private final boolean targetNeedsArea;+ private final String name;++ protected SpatialOperation(String name, boolean scoreIsMeaningful, boolean sourceNeedsArea, boolean targetNeedsArea) {+ this.name = name;+ this.scoreIsMeaningful = scoreIsMeaningful;+ this.sourceNeedsArea = sourceNeedsArea;+ this.targetNeedsArea = targetNeedsArea;+ registry.put(name, this);+ registry.put(name.toUpperCase(Locale.US), this);+ list.add( this );+ }++ public static SpatialOperation get( String v ) {+ SpatialOperation op = registry.get( v );+ if( op == null ) {+ op = registry.get(v.toUpperCase(Locale.US));+ }+ if( op == null ) {+ throw new InvalidSpatialArgument("Unknown Operation: " + v );+ }+ return op;+ }++ public static List<SpatialOperation> values() {+ return list;+ }++ public static boolean is( SpatialOperation op, SpatialOperation ... tst ) {+ for( SpatialOperation t : tst ) {+ if( op == t ) {+ return true;+ }+ }+ return false;+ }+++ // ================================================= Getters / Setters =============================================++ public boolean isScoreIsMeaningful() {+ return scoreIsMeaningful;+ }++ public boolean isSourceNeedsArea() {+ return sourceNeedsArea;+ }++ public boolean isTargetNeedsArea() {+ return targetNeedsArea;+ }++ public String getName() {+ return name;+ }++ @Override+ public String toString() {+ return name;+ }+}diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/query/UnsupportedSpatialOperation.java b/lucene/spatial/src/java/org/apache/lucene/spatial/query/UnsupportedSpatialOperation.javanew file mode 100644index 00000000000..531d59fbd83--- /dev/null+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/UnsupportedSpatialOperation.java@@ -0,0 +1,28 @@+package org.apache.lucene.spatial.query;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++/**+ * @lucene.experimental+ */+public class UnsupportedSpatialOperation extends UnsupportedOperationException {++ public UnsupportedSpatialOperation(SpatialOperation op) {+ super(op.getName());+ }+}diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/query/package-info.java b/lucene/spatial/src/java/org/apache/lucene/spatial/query/package-info.javanew file mode 100644index 00000000000..11d06c0944e--- /dev/null+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/package-info.java@@ -0,0 +1,8 @@+/**+ * Spatial Query options+ * <ul>+ * <li>useful for client side requests</li>+ * </ul>+ */+package org.apache.lucene.spatial.query;+diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.javaindex 3e419de6c68..11bd00e7ae3 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.vector;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,13 +17,8 @@* limitations under the License.*/-package org.apache.lucene.spatial.vector;-import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.exception.InvalidShapeException;-import com.spatial4j.core.exception.UnsupportedSpatialOperation;-import com.spatial4j.core.query.SpatialArgs;-import com.spatial4j.core.query.SpatialOperation;import com.spatial4j.core.shape.Circle;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Rectangle;@@ -34,6 +31,9 @@ import org.apache.lucene.queries.function.ValueSource;import org.apache.lucene.search.*;import org.apache.lucene.search.FieldCache.DoubleParser;import org.apache.lucene.spatial.SpatialStrategy;+import org.apache.lucene.spatial.query.SpatialArgs;+import org.apache.lucene.spatial.query.SpatialOperation;+import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;import org.apache.lucene.spatial.util.CachingDoubleValueSource;import org.apache.lucene.spatial.util.NumericFieldInfo;import org.apache.lucene.spatial.util.ValueSourceFilter;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestQuery.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestQuery.javaindex f51239998d7..e165a7c10ca 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestQuery.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestQuery.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,12 +17,10 @@* limitations under the License.*/-package org.apache.lucene.spatial;-import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.io.LineReader;-import com.spatial4j.core.query.SpatialArgs;-import com.spatial4j.core.query.SpatialArgsParser;+import org.apache.lucene.spatial.query.SpatialArgs;+import org.apache.lucene.spatial.query.SpatialArgsParser;import java.io.IOException;import java.io.InputStream;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.javaindex 72df4a06991..6ed9a352750 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java@@ -1,3 +1,6 @@+package org.apache.lucene.spatial;++/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,19 +18,16 @@* limitations under the License.*/-package org.apache.lucene.spatial;--import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.io.sample.SampleData;import com.spatial4j.core.io.sample.SampleDataReader;-import com.spatial4j.core.query.SpatialArgsParser;import com.spatial4j.core.shape.Shape;-import org.junit.Assert;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.StringField;import org.apache.lucene.index.IndexableField;+import org.apache.lucene.spatial.query.SpatialArgsParser;+import org.junit.Assert;import java.io.IOException;import java.io.InputStream;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java b/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.javaindex e35d848e9f9..b84d91f3315 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,14 +17,11 @@* limitations under the License.*/-package org.apache.lucene.spatial;-import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.context.simple.SimpleSpatialContext;-import com.spatial4j.core.query.SpatialArgsParser;-import com.spatial4j.core.query.SpatialOperation;import com.spatial4j.core.shape.Rectangle;-+import org.apache.lucene.spatial.query.SpatialArgsParser;+import org.apache.lucene.spatial.query.SpatialOperation;import org.apache.lucene.util.LuceneTestCase;import org.junit.Assert;import org.junit.Test;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.javaindex d9bd56262cc..72b5822d7a3 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.prefix;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,12 +17,8 @@* limitations under the License.*/-package org.apache.lucene.spatial.prefix;-import com.spatial4j.core.context.simple.SimpleSpatialContext;import com.spatial4j.core.distance.DistanceUtils;-import com.spatial4j.core.query.SpatialArgs;-import com.spatial4j.core.query.SpatialOperation;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Rectangle;import com.spatial4j.core.shape.Shape;@@ -34,6 +32,8 @@ import org.apache.lucene.spatial.SimpleSpatialFieldInfo;import org.apache.lucene.spatial.SpatialMatchConcern;import org.apache.lucene.spatial.StrategyTestCase;import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;+import org.apache.lucene.spatial.query.SpatialArgs;+import org.apache.lucene.spatial.query.SpatialOperation;import org.junit.Test;import java.io.IOException;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.javaindex d3f32b08c88..57748299bf1 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.prefix;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,11 +17,8 @@* limitations under the License.*/-package org.apache.lucene.spatial.prefix;-import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.context.simple.SimpleSpatialContext;-import com.spatial4j.core.query.SpatialArgsParser;import com.spatial4j.core.shape.Shape;import com.spatial4j.core.shape.simple.PointImpl;import org.apache.lucene.document.Document;@@ -28,6 +27,7 @@ import org.apache.lucene.document.StringField;import org.apache.lucene.spatial.SimpleSpatialFieldInfo;import org.apache.lucene.spatial.SpatialTestCase;import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;+import org.apache.lucene.spatial.query.SpatialArgsParser;import org.junit.Test;import java.io.IOException;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.javanew file mode 100644index 00000000000..67c22df09fe--- /dev/null+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java@@ -0,0 +1,65 @@+package org.apache.lucene.spatial.query;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import com.spatial4j.core.context.SpatialContext;+import com.spatial4j.core.context.simple.SimpleSpatialContext;+import com.spatial4j.core.shape.Rectangle;+import org.apache.lucene.util.LuceneTestCase;+import org.junit.Test;+++public class SpatialArgsParserTest extends LuceneTestCase {++ private SpatialContext ctx = SimpleSpatialContext.GEO_KM;++ //The args parser is only dependent on the ctx for IO so I don't care to test+ // with other implementations.++ @Test+ public void testArgsParser() throws Exception {+ SpatialArgsParser parser = new SpatialArgsParser();++ String arg = SpatialOperation.IsWithin + "(-10 -20 10 20)";+ SpatialArgs out = parser.parse(arg, ctx);+ assertEquals(SpatialOperation.IsWithin, out.getOperation());+ Rectangle bounds = (Rectangle) out.getShape();+ assertEquals(-10.0, bounds.getMinX(), 0D);+ assertEquals(10.0, bounds.getMaxX(), 0D);++ // Disjoint should not be scored+ arg = SpatialOperation.IsDisjointTo + " (-10 10 -20 20)";+ out = parser.parse(arg, ctx);+ assertEquals(SpatialOperation.IsDisjointTo, out.getOperation());++ try {+ parser.parse(SpatialOperation.IsDisjointTo + "[ ]", ctx);+ fail("spatial operations need args");+ }+ catch (Exception ex) {//expected+ }++ try {+ parser.parse("XXXX(-10 10 -20 20)", ctx);+ fail("unknown operation!");+ }+ catch (Exception ex) {//expected+ }+ }++}diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.javaindex 6dd6ef6e32a..74588b6b841 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java@@ -1,3 +1,5 @@+package org.apache.lucene.spatial.vector;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -15,12 +17,8 @@* limitations under the License.*/-package org.apache.lucene.spatial.vector;-import com.spatial4j.core.context.simple.SimpleSpatialContext;import com.spatial4j.core.exception.InvalidShapeException;-import com.spatial4j.core.query.SpatialArgs;-import com.spatial4j.core.query.SpatialOperation;import com.spatial4j.core.shape.Circle;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.simple.CircleImpl;@@ -29,6 +27,8 @@ import org.apache.lucene.search.FieldCache;import org.apache.lucene.search.Query;import org.apache.lucene.spatial.SpatialMatchConcern;import org.apache.lucene.spatial.StrategyTestCase;+import org.apache.lucene.spatial.query.SpatialArgs;+import org.apache.lucene.spatial.query.SpatialOperation;import org.apache.lucene.spatial.util.NumericFieldInfo;import org.junit.Before;import org.junit.Test;