David Smiley (@MITRE.org) wrote > On 3/10/14, 6:45 AM, "Javi" <
> javiersangrador@ > > wrote: > >>/**************/ >>/* 1. library */ >>/**************/ >> >>(1) I use "jts-1.13.jar" and "spatial4j-0.4.1.jar" >>(I think they are the latest version) > > You should only need to add JTS; spatial4j is included in Solr. Where > exactly did you put it? > > \solr-4.6\solr-webapp\webapp\WEB-INF\lib > As the other lucene librarires. If I delete from this path, solr returns > me an error, so I think it's in the proper place. > >> >>/*****************/ >>/* 2. schema.xml */ >>/*****************/ >> > <fieldType name="locationSolr" >> > class="solr.SpatialRecursivePrefixTreeFieldType" >>spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFac >>to >>ry" distErrPct="0.025" maxDistErr="0.000009" units="degrees" /> >> >>(I omit geo="true" because it is the default) >> >>... >> >> > <field name="LOCATION" type="locationSolr" indexed="true" stored="true"/> >> >>(Here I dont know what means if I add multiValued="true") > > How many points might there be in this field for a given document? 0 or > 1? Don’t set multiValued=true but if you expect possibly more than 1 then > set it to true. > > Just one point, so I omit multiValued. Thanks. > >> >>/*********************/ >>/* Document contents */ >>/*********************/ >>I have tried with 3 different content for my documents (lat-lon refers to >>Madrid, Spain): > > Um…. Just to be absolutely sure, are you adding the data in Solr’s XML > format, which is this?: > > XML Formatted Index Updates > <https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index > +Handlers#UploadingDatawithIndexHandlers-XMLFormattedIndexUpdates> > > I am not sure If I understand you properly. I index the documents with > Lucene, not with not with update handler of solr. Maybe here is the > problem. Can you set the type of the field (apart from > < > fieldType defined in schema.xml) when indexing in Lucene? Months ago, I > needed to index a LONG field, I do the trick with this aproach and it > works. > > One thing is how Solr retrieve he data (defined in schema.xml with its > <fieldType > > > ) and other thing is how lucene index the field, right? > > > The examples you give below are the *output* XML format which is not the > same as the input format. In particular you don’t give arrays of values > to Solr; you simply give more than one field element that has the same > name. > >> >> >>a) As it is WKT format, I tried "longitude latitude" (x y) >> > <doc> >> > <arr name="LOCATION"> >> > <str> > -3.69278 40.442179 > </str> >> > </arr> >> > </doc> > That should work but I don’t recommend that, as a matter of taste, if all > your data is in latitude & longitude, as opposed to projected data or any > other spatial data. > > What do you recommend? > > With "all your data is in latitude & longitude", do you refer that every > doc in the index has only the field LOCATION? If the answer is yes, then > no, there is more fields in all the documents. > >> >>b) As it is WKT format, I tried "POINT(longitude latitude) (x y) >> >> > <doc> >> > <arr name="LOCATION"> >> > <str> > POINT(-3.69278 40.442179) > </str> >> > </arr> >> > </doc> >> >>And > > Again, that should work but see my comment above. > >> >>c) I tried no WKT format by adding a comma and using "longitude,latitude" >> >> > <doc> >> > <arr name="LOCATION"> >> > <str> > 40.442179,-3.69278 > </str> >> > </arr> >> > </doc> > That is *wrong*. Remove the comma and it will then be okay. But again, > see my earlier advise on lat & lon data. > >> >>d) I tried no WKT format by adding a comma and using "latitude,longitude" >> >> > <doc> >> > <arr name="LOCATION"> >> > <str> > -3.69278,40.442179 > </str> >> > </arr> >> > </doc> > But that isn’t latitude then longitude of Madrid; you have it reversed. > “latitude,longitude” of Madrid is “40.442719,-3.69278”. > >> >>/*****************/ >>/* My solr query */ >>/*****************/ >> >>a) >>_Description: This POLYGON (in WKT format, so "longitude latitude") is a >>triangle that cover Madrid at all, so my point would be inside them. >>_Result: Query return 0 documents (which is wrong). >> >>http://localhost:8983/solr/pisos22/select?q=*%3A*& >>fl=LOCATION& >>wt=xml& >>indent=true& >>fq=LOCATION:"IsWithin(POLYGON(( >>-3.732605 40.531415, >>-3.856201 40.336993, >>-3.493652 40.332806, >>-3.732605 40.531415 >>))) distErrPct=0" >> >>b) >>_Descripcion: This POLYGON (in WKT format, so "longitude latitude") is a >>rectangle out of Madrid, so my point would not be inside them. >>_Result: Query return 0 documents (which is correct). >> >>http://localhost:8983/solr/pisos22/select?q=*%3A*& >>fl=LOCATION& >>wt=xml& >>indent=true& >>fq=LOCATION:"IsWithin(POLYGON(( >>-4.0594 40.8708, >>-4.0621 40.7211 , >>-3.8095 40.7127, >>-3.8232 40.8687, >>-4.0594 40.8708 >>))) distErrPct=0" >> >>***I also tried modifying the order of lat/lon but I am not able to find >>out >>the solution to make it work. > > The “x y” order looks good. “IsWithin” should work but if all your > indexed data is points then use “Intersects” which is much faster. > > As a sanity check can you simply do a {!geofilt} query with the “pt” set > to madrid and a hundred kilometers or whatever? > > I have tried {!geofilt pt=40.442179,-3.69278 sfield=LOCATION d=100} in FQ > and returned 0 docs :((( > > ~ David -- View this message in context: http://lucene.472066.n3.nabble.com/Solr-spatial-search-within-the-polygon-tp4101147p4122623.html Sent from the Solr - User mailing list archive at Nabble.com.