Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-9270: spatialContextFactory now accepts "JTS" alias. Spatial config attributes with old package names are now rewritten with a warning.

David Smiley360b9a35282a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ba21abb1886..8b67d5a4170 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -91,6 +91,10 @@ New Features
* SOLR-9090: Add directUpdatesToLeadersOnly flag to solrj CloudSolrClient.
(Marvin Justice, Christine Poerschke)
+* SOLR-9270: Allow spatialContextFactory to be simply "JTS". And if any spatial params include the old
+ Spatial4j package "com.spatial4j.core" it is rewritten to "org.locationtech.spatial4j" with a warning.
+ (David Smiley)
+
Bug Fixes
----------------------
@@ -611,6 +615,10 @@ Upgrading from Solr 5.x
* SolrJ no longer includes DateUtil. If for some reason you need to format or parse dates, simply use Instant.format()
and Instant.parse().
+* If you are using an RPT or other spatial field referencing Spatial4j in its configuration, then replace the string
+ "com.spatial4j.core" with "org.locationtech.spatial4j". Consider updating direct to Solr 6.2 which accepts the
+ old value, albeit with a warning.
+
Detailed Change List
----------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
index 12fcea35f28..10756daa37a 100644
--- a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
+++ b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
@@ -119,7 +119,23 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extend
protected void init(IndexSchema schema, Map<String, String> args) {
super.init(schema, args);
- if(ctx==null) { // subclass can set this directly
+ if (ctx==null) { // subclass can set this directly
+ final String CTX_PARAM = "spatialContextFactory";
+ final String OLD_SPATIAL4J_PREFIX = "com.spatial4j.core";
+ final String NEW_SPATIAL4J_PREFIX = "org.locationtech.spatial4j";
+ for (Map.Entry<String, String> argEntry : args.entrySet()) {
+ // "JTS" is a convenience alias
+ if (argEntry.getKey().equals(CTX_PARAM) && argEntry.getValue().equals("JTS")) {
+ argEntry.setValue("org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory");
+ continue;
+ }
+ // Warn about using old Spatial4j class names
+ if (argEntry.getValue().contains(OLD_SPATIAL4J_PREFIX)) {
+ log.warn("Replace '" + OLD_SPATIAL4J_PREFIX + "' with '" + NEW_SPATIAL4J_PREFIX + "' in your schema.");
+ argEntry.setValue(argEntry.getValue().replace(OLD_SPATIAL4J_PREFIX, NEW_SPATIAL4J_PREFIX));
+ }
+ }
+
//Solr expects us to remove the parameters we've used.
MapListener<String, String> argsWrap = new MapListener<>(args);
ctx = SpatialContextFactory.makeSpatialContext(argsWrap, schema.getResourceLoader().getClassLoader());