Hello Jim, By the way, using GeohashPrefixTree.getMaxLevelsPossible() is usually an extreme choice. Instead you probably want to choose only as many levels needed for your distance tolerance. See SpatialPrefixTreeFactory which you can use outright or borrow the code it uses.
Looking at your code, I see you are coding against Solr directly in Java instead of where most people do this as an HTTP web service. But it’s unclear in what context your code runs because you are getting into the guts of things that you normally don’t have to do, even if your using SolrJ or writing some sort of UpdateRequestProcessor. Simply configure the field type in schema.xml appropriately, and then to index a point simply give Solr a string for the field in “latitude, longitude” format. I don’t know why you are using field.tokenStream(analyzer) for the field value — that is clearly wrong and the cause of the error. I think your confusion more has to do with differences in coding to Lucene versus Solr; this being an actual spatial concern. You referenced “SpatialDemoUpdateProcessorFactory” so I see you have looked at SolrSpatialSandbox on GitHub. That particular URP should get some warnings added to it in the code to suggest that you probably should do what it does. If you look at the solrconfig.xml that configures it, there is a warning as follows: <!-- spatial Only needed for an SpatialDemoUpdateProcessorFactory which copies spatial objects from one field to other spatial fields in object form to avoid redundant/inefficient string to spatial object de-serialization. --> Even if you have a similar circumstance, you’re code doesn’t quite look like this URP. You shouldn’t need to reference the SpatialStrategy, for example. ~ David From: <Beale>, "Jim (US-KOP)" <jim.be...@hibu.com<mailto:jim.be...@hibu.com>> Date: Friday, January 10, 2014 at 12:15 PM To: "solr-user@lucene.apache.org<mailto:solr-user@lucene.apache.org>" <solr-user@lucene.apache.org<mailto:solr-user@lucene.apache.org>> Cc: "Smiley, David W." <dsmi...@mitre.org<mailto:dsmi...@mitre.org>> Subject: Indexing spatial fields into SolrCloud (HTTP) I am porting an application from Lucene to Solr which makes use of spatial4j for distance searches. The Lucene version works correctly but I am having a problem getting the Solr version to work in the same way. Lucene version: SpatialContext geoSpatialCtx = SpatialContext.GEO; geoSpatialStrategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree( geoSpatialCtx, GeohashPrefixTree.getMaxLevelsPossible()), DocumentFieldNames.LOCATION); Point point = geoSpatialCtx.makePoint(lon, lat); for (IndexableField field : geoSpatialStrategy.createIndexableFields(point)) { document.add(field); } //Store the field document.add(new StoredField(geoSpatialStrategy.getFieldName(), geoSpatialCtx.toString(point))); Solr version: Point point = geoSpatialCtx.makePoint(lon, lat); for (IndexableField field : geoSpatialStrategy.createIndexableFields(point)) { try { solrDocument.addField(field.name(), field.tokenStream(analyzer)); } catch (IOException e) { LOGGER.error("Failed to add geo field to Solr index", e); } } // Store the field solrDocument.addField(geoSpatialStrategy.getFieldName(), geoSpatialCtx.toString(point)); The server-side error is as follows: Caused by: com.spatial4j.core.exception.InvalidShapeException: Unable to read: org.apache.lucene.spatial.prefix.PrefixTreeStrategy$CellTokenStr\ eam@0 at com.spatial4j.core.io.ShapeReadWriter.readShape(ShapeReadWriter.java:48) at com.spatial4j.core.context.SpatialContext.readShape(SpatialContext.java:195) at org.apache.solr.schema.AbstractSpatialFieldType.parseShape(AbstractSpatialFieldType.java:142) I’ve seen David Smiley’s sample code, specifically the class, SpatialDemoUpdateProcessorFactory, but I can’t say that I was able to benefit from it at all. What I’m trying to do seems like it should be easy – just to index a point for distance searching – but I’m obviously missing something. Any ideas? Thanks, Jim The information contained in this email message, including any attachments, is intended solely for use by the individual or entity named above and may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you must not read, use, disclose, distribute or copy any part of this communication. If you have received this communication in error, please immediately notify me by email and destroy the original message, including any attachments. Thank you.