Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr spatial search with input point and query which polygon within

I have some polygons indexed in Solr. Is it possible to query with a point(lat,lon) and see which polygon has that point inside?

like image 477
user2836163 Avatar asked Mar 23 '23 01:03

user2836163


1 Answers

Yes it is possible and described here: http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 Your Solr Version must be 4 or higher and you have to import the JTS jar-file which you can get from http://sourceforge.net/projects/jts-topo-suite/ You have to define a field with a fieldType of location_rpt

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

in the schema.xml. Then you have to index the polygons like:

<field name="geo">POLYGON((-10 30, -40 40, -10 -20, 40 20, 0 0, -10 30))</field>

But i think you already did it this way because you wrote that you already have them indexed.

For the query you simply have to use the filter query fq=geo:"Intersects(10.12 50.02)" where 10.12 and 50.02 represent the latitude and longitude of your point.

like image 178
user2894821 Avatar answered Mar 24 '23 14:03

user2894821