Configure SOLR for Spatial Search Setup
Configure SOLR for Spatial Search Setup
----------------------------------------------------
One of our projects requires the spatial search to find the closest records for given address OR zipcodes. So we decided to use SOLR for performing spaital search based on latitude & longitude for getting the closest records.
This blog describes on SOLR configuration for location based spatial search and how to run queries on SOLR.
You can download latest SOLR from here : http://apache.mesi.com.ar/lucene/solr/
Schema Changes :
To add location data (latitude, longitude) in documents, we need to update the schema.xml file. We need to add a new field type (specifically used for geospatial searching). In case it's not already present (depends on SOLR version), we have to add the below fieldType definition to the schema.xml file.
<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
FieldType definition is done. Now we need to define the fields for location data.
<field name="latlon" type="location" indexed="true" stored="true" />
indexed=true makes a field searchable (and sortable and facetable). For eg, if you have a field named test1 with indexed=true, then you can search it like q=test1:foo, where foo is the value you are searching for.
stored=true means you can retrieve the field when you search.
Indexing Location Data