Apache Lucene open-source search software
SOLR-6904: remove deprecated spatial Circle & Rect syntax FYI these weren't used often and were replaced with supported syntaxes in v4.3.
David Wayne Smileyc0707926dfd2
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 23508bd2932..e67ededcc69 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -153,6 +153,11 @@ Upgrading from Solr 4.xsolrconfig.xml. Solr defaults to using NRT searchers regardless of the value in configurationand a warning is logged on startup if the solrconfig.xml has <nrtMode> specified.+* There was an old spatial syntax to specify a circle using Circle(x,y d=...) which should be+ replaced with simply using {!geofilt} (if you can) or BUFFER(POINT(x y),d). Likewise a rect syntax+ comprised of minX minY maxX maxY that should now be replaced with+ ENVELOPE(minX, maxX, maxY, minY).+Detailed Change List----------------------@@ -684,6 +689,8 @@ Other Changes* SOLR-6496: LBHttpSolrClient stops server retries after the timeAllowed threshold is met.(Steve Davids, Anshum Gupta)+* SOLR-6904: Removed deprecated Circle & rect syntax. See upgrading notes. (David Smiley)+================== 4.10.3 ==================Bug Fixesdiff --git a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.javaindex 3441353d4dc..f55158759e5 100644--- a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java+++ b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java@@ -23,7 +23,6 @@ import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.List;-import java.util.Locale;import java.util.Map;import java.util.Set;import java.util.TreeSet;@@ -36,7 +35,6 @@ import com.google.common.cache.CacheBuilder;import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.context.SpatialContextFactory;import com.spatial4j.core.distance.DistanceUtils;-import com.spatial4j.core.io.LegacyShapeReadWriterFormat;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Rectangle;import com.spatial4j.core.shape.Shape;@@ -115,17 +113,6 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extendprotected void init(IndexSchema schema, Map<String, String> args) {super.init(schema, args);- //replace legacy rect format with ENVELOPE- String wbStr = args.get("worldBounds");- if (wbStr != null && !wbStr.toUpperCase(Locale.ROOT).startsWith("ENVELOPE")) {- log.warn("Using old worldBounds format? Should use ENVELOPE(xMin, xMax, yMax, yMin).");- String[] parts = wbStr.split(" ");//"xMin yMin xMax yMax"- if (parts.length == 4) {- args.put("worldBounds",- "ENVELOPE(" + parts[0] + ", " + parts[2] + ", " + parts[3] + ", " + parts[1] + ")");- } //else likely eventual exception- }-//Solr expects us to remove the parameters we've used.MapListener<String, String> argsWrap = new MapListener<>(args);ctx = SpatialContextFactory.makeSpatialContext(argsWrap, schema.getResourceLoader().getClassLoader());@@ -237,18 +224,17 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extendprotected Shape parseShape(String str) {if (str.length() == 0)throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "empty string shape");- //In Solr trunk we only support "lat, lon" (or x y) as an additional format; in v4.0 we do the- // weird Circle & Rect formats too (Spatial4j LegacyShapeReadWriterFormat).- try {- Shape shape = LegacyShapeReadWriterFormat.readShapeOrNull(str, ctx);- if (shape != null)- return shape;- return ctx.readShapeFromWkt(str);- } catch (Exception e) {- String message = e.getMessage();- if (!message.contains(str))- message = "Couldn't parse shape '" + str + "' because: " + message;- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, message, e);+ if (Character.isLetter(str.charAt(0))) {//WKT starts with a letter+ try {+ return ctx.readShapeFromWkt(str);+ } catch (Exception e) {+ String message = e.getMessage();+ if (!message.contains(str))+ message = "Couldn't parse shape '" + str + "' because: " + message;+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, message, e);+ }+ } else {+ return SpatialUtils.parsePointSolrException(str, ctx);}}diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml b/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xmlindex df8827ba398..673f3b3d862 100644--- a/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml+++ b/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml@@ -47,9 +47,6 @@<fieldType name="pointvector" class="solr.SpatialPointVectorFieldType"numberType="tdouble" distanceUnits="degrees"/>- <fieldType name="stqpt_u_oldworldbounds" class="solr.SpatialTermQueryPrefixTreeFieldType"- geo="false" distCalculator="cartesian^2" worldBounds="0 0 1000 1000" distanceUnits="degrees"/>-<fieldType name="bbox" class="solr.BBoxField"numberType="tdoubleDV" distanceUnits="degrees"/></types>diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.javaindex 690ad742d21..c086b7ad4d0 100644--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java@@ -26,11 +26,8 @@ import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.distance.DistanceUtils;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Rectangle;-import com.spatial4j.core.shape.impl.RectangleImpl;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.SolrException;-import org.apache.solr.schema.AbstractSpatialFieldType;-import org.apache.solr.schema.IndexSchema;import org.apache.solr.util.SpatialUtils;import org.junit.Before;import org.junit.BeforeClass;@@ -72,13 +69,13 @@ public class TestSolr4Spatial extends SolrTestCaseJ4 {public void testBadShapeParse400() {assertQEx(null, req("fl", "id," + fieldName, "q", "*:*", "rows", "1000",- "fq", "{!field f="+fieldName+"}Intersects(NonexistentShape(89.9,-130 d=9))"), 400);+ "fq", "{!field f=" + fieldName + "}Intersects(NonexistentShape(89.9,-130 d=9))"), 400);assertQEx(null, req("fl", "id," + fieldName, "q", "*:*", "rows", "1000",- "fq", "{!field f="+fieldName+"}Intersects(NonexistentShape(89.9,-130 d=9"), 400);//missing parens+ "fq", "{!field f=" + fieldName + "}Intersects(NonexistentShape(89.9,-130 d=9"), 400);//missing parensassertQEx(null, req("fl", "id," + fieldName, "q", "*:*", "rows", "1000",- "fq", "{!field f="+fieldName+"}Intersectssss"), 400);+ "fq", "{!field f=" + fieldName + "}Intersectssss"), 400);ignoreException("NonexistentShape");try {@@ -158,8 +155,8 @@ public class TestSolr4Spatial extends SolrTestCaseJ4 {assertU(commit());assertQ(req(- "fl", "id," + fieldName, "q", "*:*", "rows", "1000",- "fq", "{!bbox sfield="+fieldName+" pt="+IN+" d=9}"),+ "fl", "id," + fieldName, "q", "*:*", "rows", "1000",+ "fq", "{!bbox sfield=" + fieldName + " pt=" + IN + " d=9}"),"//result/doc/*[@name='" + fieldName + "']//text()='" + OUT + "'");}@@ -361,37 +358,6 @@ public class TestSolr4Spatial extends SolrTestCaseJ4 {);}- @Test- public void solr4OldShapeSyntax() throws Exception {- assumeFalse("Mostly just valid for prefix-tree", fieldName.equals("pointvector"));-- //we also test that the old syntax is parsed in worldBounds in the schema- {- IndexSchema schema = h.getCore().getLatestSchema();- AbstractSpatialFieldType type = (AbstractSpatialFieldType) schema.getFieldTypeByName("stqpt_u_oldworldbounds");- SpatialContext ctx = type.getStrategy("foo").getSpatialContext();- assertEquals(new RectangleImpl(0, 1000, 0, 1000, ctx), ctx.getWorldBounds());- }-- //syntax supported in Solr 4 but not beyond- // See Spatial4j LegacyShapeReadWriterFormat- String rect = "-74.093 41.042 -69.347 44.558";//minX minY maxX maxY- String circ = "Circle(4.56,1.23 d=0.0710)";-- //show we can index this (without an error)- assertU(adoc("id", "rect", fieldName, rect));- if (!fieldName.equals("bbox")) {- assertU(adoc("id", "circ", fieldName, circ));- assertU(commit());- }-- //only testing no error- assertJQ(req("q", "{!field f=" + fieldName + "}Intersects(" + rect + ")"));- if (!fieldName.equals("bbox")) {- assertJQ(req("q", "{!field f=" + fieldName + "}Intersects(" + circ + ")"));- }- }-@Testpublic void testBadScoreParam() throws Exception {assertQEx("expect friendly error message",