Hi all. I need your help! I have read every post about Spatial in Solr because I need to check if a point (latitude,longitude) is inside a Polygon.
/**************/ /* 1. library */ /**************/ (1) I use "jts-1.13.jar" and "spatial4j-0.4.1.jar" (I think they are the latest version) /*****************/ /* 2. schema.xml */ /*****************/ <fieldType name="locationSolr" class="solr.SpatialRecursivePrefixTreeFieldType" spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFacto 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") /*********************/ /* Document contents */ /*********************/ I have tried with 3 different content for my documents (lat-lon refers to Madrid, Spain): a) As it is WKT format, I tried "longitude latitude" (x y) <doc> <arr name="LOCATION"> <str>-3.69278 40.442179</str> </arr> </doc> 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 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> 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> /*****************/ /* 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.