Geolocation
Links
LocalSolr offers geographical searching capabilities to your search engine.
http://code.google.com/p/forage/wiki/GeoSearch forage - Search Abstraction Layer
developerWorks, Location-aware search with Apache Lucene and Solr.
LocalSolr
Install
Follow the normal Install instructions.
Download
locallucene_r2.0.tar.gzandlocalsolr_r2.0.tar.gzfrom http://sourceforge.net/projects/locallucene/Extract the following
jarfiles from the archives and add to thelibfolder in yoursolr/home(e.g. in the Install, thelibfolder would be/home/repository/solr/default/lib/):geoapi-nogenerics-2.1-M2.jargt2-referencing-2.3.1.jarjsr108-0.01.jarjunit.jarlocallucene.jarlocalsolr.jar
Update
solrconfig.xml. Here is a patch file showing the configuration to insert: solrconfig.xml.patchAdd the following field definitions to your
schema.xmlfile:<field name="lat" type="sdouble" indexed="true" stored="true"/><!-- must match the latField in solrconfig.xml --> <field name="lng" type="sdouble" indexed="true" stored="true"/><!-- must match the lngField in solrconfig.xml --> <field name="geo_distance" type="sdouble"/> <!-- Optional but used for distributed searching --> <dynamicField name="_local*" type="sdouble" indexed="true" stored="true"/><!-- used internally by localsolr -->
If you want to use the demo data (or the LocalSolr demo data)…
Add the following field definitions to your
schema.xmlfile:<field name="cinema" type="text" indexed="true" stored="true"/> <field name="street" type="text" indexed="true" stored="true" omitNorms="true"/> <field name="city" type="text_ws" indexed="true" stored="true" multiValued="true" omitNorms="true"/> <field name="zip" type="text" indexed="true" stored="true"/> <field name="doctype" type="text" indexed="true" stored="true"/>
Extract
post.jarfrom theapache-solr-1.3.0.ziparchive, folderapache-solr-1.3.0/example/exampledocs/.Get a copy of the XML demo data: devon.xml
Start SOLR and add the data to SOLR:
java -Durl=http://localhost:8080/solr/update -jar post.jar devon.xml
Here is a python script which you can use to test the search: search-http-get.py.
To install the LocalSolr demo data, download http://www.nsshutdown.com/solr-example.tgz
Extract
ny_cinemas.xmlfrom the archive folder,solr-example.tar/solr-example/data/ny_cinemas.xml.Start SOLR and add the data to SOLR:
java -Durl=http://localhost:8080/solr/update -jar post.jar ny_cinemas.xml
Sort
To sort by distance simply add:
&sort=geo_distance asc
For sample code see search.py