That’s pretty weird. It appears that somehow a Spatial4j Point class is having it’s toString() called on it (which looks like "Pt(x=-72.544123,y=41.822225)" ) and then Spatial4j is trying to parse this which isn’t in a valid format — the toString is more debug-ability. Your SolrJ code looks totally fine. Perhaps you’ve got some funky UpdateRequestProcessor from experimentation you’ve done that’s parsing then toString’ing it? And also, your stack trace should have more to it than what you present here. It may be on the server-side versus the HTTP error page which can get abbreviated.
~ David From: <Beale>, "Jim (US-KOP)" <jim.be...@hibu.com<mailto:jim.be...@hibu.com>> Date: Wednesday, February 12, 2014 at 2:05 PM To: "Smiley, David W." <dsmi...@mitre.org<mailto:dsmi...@mitre.org>>, "solr-user@lucene.apache.org<mailto:solr-user@lucene.apache.org>" <solr-user@lucene.apache.org<mailto:solr-user@lucene.apache.org>> Subject: RE: Indexing spatial fields into SolrCloud (HTTP) Hi David, I finally got back to this again, after getting sidetracked for a couple of weeks. I implemented things in accordance with my understanding of what you wrote below. Using SolrJ, the code to index the spatial field is as follows, privatevoid addSpatialField(double lat, double lon, SolrInputDocument document) { StringBuilder sb = new StringBuilder(); sb.append(lat).append(",").append(lon); document.addField("location", sb.toString()); } Using Solr 4.3.1 and spatial4j 0.3, I am getting the following error in the solr logs: 1518436 [qtp1529118084-24] ERROR org.apache.solr.core.SolrCore â org.apache.solr.common.SolrException: com.spatial4j.core.exception.InvalidShapeException: Unable to read: Pt(x=-72.544123,y=41.822225) at org.apache.solr.schema.AbstractSpatialFieldType.parseShape(AbstractSpatialFieldType.java:144) at org.apache.solr.schema.AbstractSpatialFieldType.createFields(AbstractSpatialFieldType.java:118) spatial4j 0.3 is looking for something like POINT but Solr is converting my “lat,long” to Pt(x=-72.544123,y=41.822225). Version mismatch? Thanks in advance for your help! Jim Beale From: Smiley, David W. [mailto:dsmi...@mitre.org] Sent: Monday, January 13, 2014 11:30 AM To: Beale, Jim (US-KOP); solr-user@lucene.apache.org<mailto:solr-user@lucene.apache.org> Subject: Re: Indexing spatial fields into SolrCloud (HTTP) 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. 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.