LocalSolr
Expert Level
LocalSolr is a port of the LocalLucene library to the Solr search server. LocalSolr offers geographical searching capabilities to your search engine.
To customize local solr you simple need to alter a few configuration files.
Configuration solr/conf/solrconfig.xml
<!-- Configure Indexer -->
<updateRequestProcessor>
<factory name="standard" class="solr.ChainedUpdateProcessorFactory"
default="true">
<chain class="com.pjaol.search.solr.update.LocalUpdateProcessorFactory">
<str name="latField">lat</str> <!-- The field used to store
your latitude -->
<str name="lngField">lng</str> <!-- The field used to store
your longitude -->
<int name="startTier">9</int> <!-- The lowest level to store data at,
level 9 covers about 100 miles,
level 5 about 1000 -->
<int name="endTier">15</int> <!-- The highest / granular level you want
to search at, 15 is about 1 mile -->
</chain>
<chain class="solr.LogUpdateProcessorFactory" >
<!-- <int name="maxNumToLog">100</int> -->
</chain>
<chain class="solr.RunUpdateProcessorFactory" />
</factory>
</updateRequestProcessor>
<!-- configure the localsolr search component -->
<searchComponent name="localsolr"
class="com.pjaol.search.solr.component.LocalSolrQueryComponent" >
<str name="latField">lat</str><!-- The field used to store your latitude -->
<str name="lngField">lng</str><!-- The field used to store your longitude -->
</searchComponent>
<!-- localsolr request handler -->
<requestHandler name="geo"
class="org.apache.solr.handler.component.SearchHandler">
<arr name="components">
<str>localsolr</str>
<str>facet</str>
<str>mlt</str>
<str>highlight</str>
<str>debug</str>
</arr>
</requestHandler>
Edit solr/conf/schema.xml
<!-- local lucene field types -->
<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 -->
The _local* fields can be turned to stored="false" if you don't want
these generated fields to be displayed. They are used internally by localsolr to find areas quickly.
Other wise you could potentially use them to find density of results in an area.
Making a request to localsolr
/solr/select?&qt=geo&lat=xx.xx&long=yy.yy&q=abc&radius=zz
qt query template configured in the solrconfig.xml in this example it's 'geo'
lat latitude in degrees
long longitude in degrees
q solr query
radius in miles.
- Login to post comments












