Index: lucene/spatial/src/java/org/apache/lucene/spatial/query/UnsupportedSpatialOperation.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/query/UnsupportedSpatialOperation.java (revision )
+++ lucene/spatial/src/java/org/apache/lucene/spatial/query/UnsupportedSpatialOperation.java (revision )
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+package org.apache.lucene.spatial.query;
+
+/**
+ * @lucene.experimental
+ */
+public class UnsupportedSpatialOperation extends UnsupportedOperationException {
+
+ public UnsupportedSpatialOperation(SpatialOperation op) {
+ super(op.getName());
+ }
+}
Index: lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java (revision 1355226)
+++ lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java (revision )
@@ -19,10 +19,9 @@
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;
Index: lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java (revision 1355226)
+++ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java (revision )
@@ -18,7 +18,6 @@
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.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;
Index: lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java (revision 1355226)
+++ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java (revision )
@@ -17,9 +17,6 @@
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.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;
Index: lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java (revision 1355226)
+++ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java (revision )
@@ -17,13 +17,13 @@
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}.
Index: lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java (revision 1355226)
+++ lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java (revision )
@@ -19,8 +19,6 @@
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.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;
Index: lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java (revision )
+++ lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java (revision )
@@ -0,0 +1,134 @@
+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.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( SpatialContext.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:
+ *
sqrt(shape.bbox.area)/2
+ * 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;
+ }
+}
Index: lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java (revision 1355226)
+++ lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java (revision )
@@ -18,7 +18,6 @@
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.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 @@
/**
* 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);
Index: lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.java (revision )
+++ lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgsParser.java (revision )
@@ -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 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 parseMap(String body) {
+ Map map = new HashMap();
+ 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;
+ }
+}
Index: lucene/spatial/src/java/org/apache/lucene/spatial/query/package-info.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/query/package-info.java (revision )
+++ lucene/spatial/src/java/org/apache/lucene/spatial/query/package-info.java (revision )
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/**
+ * Spatial Query options
+ *
+ * - useful for client side requests
+ *
+ */
+package org.apache.lucene.spatial.query;
+
Index: lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java (revision 1355226)
+++ lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java (revision )
@@ -19,7 +19,6 @@
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.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;
Index: lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java (revision 1355226)
+++ lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java (revision )
@@ -19,8 +19,6 @@
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.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;
Index: lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTree.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTree.java (revision 1355226)
+++ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTree.java (revision )
@@ -63,7 +63,7 @@
}
/**
- * 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.5
Index: lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestQuery.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestQuery.java (revision 1355226)
+++ lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestQuery.java (revision )
@@ -19,8 +19,8 @@
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;
Index: lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java (revision )
+++ lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java (revision )
@@ -0,0 +1,47 @@
+package org.apache.lucene.spatial.query;
+
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.shape.Rectangle;
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
+
+
+public class SpatialArgsParserTest extends LuceneTestCase {
+
+ private SpatialContext ctx = SpatialContext.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
+ }
+ }
+
+}
Index: lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java (revision 1355226)
+++ lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java (revision )
@@ -16,9 +16,9 @@
*/
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 +26,15 @@
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;
/**
Index: lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java (revision )
+++ lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java (revision )
@@ -0,0 +1,106 @@
+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.
+ */
+public class SpatialOperation implements Serializable {
+ // Private registry
+ private static final Map registry = new HashMap();
+ private static final List list = new ArrayList();
+
+ // 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 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;
+ }
+}
Index: lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java (revision 1355226)
+++ lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java (revision )
@@ -19,9 +19,6 @@
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.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;
Index: lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java (revision 1355226)
+++ lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java (revision )
@@ -21,13 +21,13 @@
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;