You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/01/13 15:17:19 UTC

svn commit: r1651351 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java core/src/test-files/solr/collection1/conf/schema-spatial.xml core/src/test/org/apache/solr/search/TestSolr4Spatial.java

Author: dsmiley
Date: Tue Jan 13 14:17:18 2015
New Revision: 1651351

URL: http://svn.apache.org/r1651351
Log:
SOLR-6904: remove deprecated spatial Circle & Rect syntax
FYI these weren't used often and were replaced with supported syntaxes in v4.3.

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
    lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1651351&r1=1651350&r2=1651351&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Jan 13 14:17:18 2015
@@ -153,6 +153,11 @@ Upgrading from Solr 4.x
   solrconfig.xml. Solr defaults to using NRT searchers regardless of the value in configuration
   and 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 Fixes

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java?rev=1651351&r1=1651350&r2=1651351&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java Tue Jan 13 14:17:18 2015
@@ -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.CacheBuil
 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 AbstractSpatialFie
   protected 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 AbstractSpatialFie
   protected 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);
     }
   }
 

Modified: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml?rev=1651351&r1=1651350&r2=1651351&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml Tue Jan 13 14:17:18 2015
@@ -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>

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java?rev=1651351&r1=1651350&r2=1651351&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java Tue Jan 13 14:17:18 2015
@@ -26,11 +26,8 @@ import com.spatial4j.core.context.Spatia
 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 So
   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 parens
     assertQEx(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 So
     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 + "'");
   }
 
@@ -362,37 +359,6 @@ public class TestSolr4Spatial extends So
   }
 
   @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 + ")"));
-    }
-  }
-
-  @Test
   public void testBadScoreParam() throws Exception {
     assertQEx("expect friendly error message",
         "none",