Problem/Motivation

On Solr 4.x there are new spatial features: http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4

Improvements by adding this fieldType:

  • It will allow many spatial features, including:
  • Indexing shapes, such as circles and rectangles
  • Index non-point shapes as well as points
  • Multi-value distance sort / score boost
  • Configurable precision - enhances performance
  • Fast filtering
  • Sort by distance - without geodist()

Why it is a bug?

I added the new fieldType to a fresh core0 and everything worked fine. However, adding it to our schema it returns an error (this is reason why I opened the issue as 'bug report' instead of 'feature request'):


3568 [coreLoadExecutor-3-thread-2] ERROR org.apache.solr.core.CoreContainer  – null:java.lang.NoClassDefFoundError: com/vividsolutions/jts/geom/Geometry
	at com.spatial4j.core.context.jts.JtsSpatialContextFactory.newSpatialContext(JtsSpatialContextFactory.java:30)
	at com.spatial4j.core.context.SpatialContextFactory.makeSpatialContext(SpatialContextFactory.java:83)
	at org.apache.solr.schema.AbstractSpatialFieldType.init(AbstractSpatialFieldType.java:95)
	at org.apache.solr.schema.AbstractSpatialPrefixTreeFieldType.init(AbstractSpatialPrefixTreeFieldType.java:43)
	at org.apache.solr.schema.SpatialRecursivePrefixTreeFieldType.init(SpatialRecursivePrefixTreeFieldType.java:37)
	at org.apache.solr.schema.FieldType.setArgs(FieldType.java:164)
	at org.apache.solr.schema.FieldTypePluginLoader.init(FieldTypePluginLoader.java:141)
	at org.apache.solr.schema.FieldTypePluginLoader.init(FieldTypePluginLoader.java:43)
	at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:190)
	at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:476)
	at org.apache.solr.schema.IndexSchema.<init>(IndexSchema.java:176)
	at org.apache.solr.schema.ClassicIndexSchemaFactory.create(ClassicIndexSchemaFactory.java:62)
	at org.apache.solr.schema.IndexSchemaFactory.buildIndexSchema(IndexSchemaFactory.java:36)
	at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:946)
	at org.apache.solr.core.CoreContainer.create(CoreContainer.java:984)
	at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:597)
	at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:592)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: com.vividsolutions.jts.geom.Geometry
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
	... 25 more

As it works on the fresh core0, then it means there is no need to download additional files. I tried to modify the config files provided by the module apachesolr adding all available libs that comes on Solr, but no luck.

Comments

kirikintha’s picture

I am playing around with solr 4.5 and found that I had the same issue.

I found this doc, and it seems to have a potential solution:
http://www.duraibalusamy.com/2013/06/solr-430-spatial-search-setup-for.html

I downloaded from here:

http://www.vividsolutions.com/jts/download.htm

and installed into solr-webapp/webapp/WEB-INF/lib

And now the error has been mitigated. I am not sure this is a bug per-se, but a support request? I am not sure why solr 4.5 would not ship with the proper .jar files.

Nick_vh’s picture

Project: Apache Solr Search » Apache Solr Common Configurations
Version: 7.x-1.x-dev »
Issue summary: View changes

Moving to Common Configuration

Mac_Weber’s picture

I have using a similar configuration than #1. I'm not using JTS because I'm not doing any extra geometry computations on Solr, I'm only using its native spatial search using circle intersects, which does not need this additional library.

I'm not sure if the same config would work for Solr 3.x.

There is also an update on Solr 4.5 which supports geodist() again. This allows spatial search with score without weird hacks.

Nick_vh’s picture

Can we get a patch here so we can get a better understanding of what you are trying to achieve?

geerlingguy’s picture

Category: Bug report » Feature request

I'm getting a similar issue:

Error loading core:java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: com/vividsolutions/jts/geom/CoordinateSequenceFactory

I wanted multi-value geolocation support, so I modified schema.xml to include:

    <fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
               spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
               distErrPct="0.025"
               maxDistErr="0.000009"
               units="degrees" />

and then I updated the locm_* dynamic field to use the new RPT field type:

<dynamicField name="locm_*" type="location_rpt" indexed="true"  stored="true" multiValued="true"/>

It looks like using the RPT field type (as mentioned here) with the above spatialContextFactory requires JTS as mentioned earlier in this issue, and in the solr docs (latest version is 1.13 as of this writing). Also check out the property docs in SpatialRecursivePrefixTreeFieldType (abbreviated as RPT).

I think this should be a feature request—if we want some of the benefits offered by SpatialRecursivePrefixTreeFieldType (like more advanced polygons, filtering, multi-value fields, etc.), we would need to have support added in schema.xml (at least the fieldType as above), and then documentation added elsewhere as to how to install JTS on your solr server(s), and how to switch the locm/locs fields to use location_rpt.

geerlingguy’s picture

Also note that simply removing the spatialContextFactory property entirely doesn't require the installation of JTS, and allows for multi-value geo field search, at least. So if that's all you want, you can just add the rule without that property, and everything should work with Apache Solr > 4.5.

See: Multi-value spatial search with Solr 4.x and Drupal 7.

gbirch’s picture

Mac_Weber’s picture

Status: Active » Closed (outdated)

I think we can close this issue as outdated, as spatial search has changed a lot from 4.x to 4.5 and to the current release 6.x. Many features that required "tricks" are now in Solr core and they are done a bit different than in past versions.