Kurt Jarchow's Blog

December 14, 2008

SOLR, Drupal, and GEO Spatial Results

Filed under: Uncategorized — Tags: , , , — Kurt Jarchow @ 10:05 pm

Our search needed to preform typical longitude and latitude geo-radius spatial results (I’ve mashed up all of those keywords because I really am not sure what someone will search for to find this post, apologies for the grammar!).  Since I took on SOLR as our search engine I needed to find an elegant solution.

After some search, I found the holy grail: Local SOLR.  Not finding much instruction on the official site, I found a great blog post with an explanation and example.  Its fairly easy to install and integrate into drupal.

  1. Extract the files and copy them into your solr directory (if your main solr instance is under “example”, make it “example2″.
  2. Stop your sorl instance (I’m assuming your on a dev box!) and start the local solr.
  3. Test to see if its working using the localhost cinema example.
  4. If it works find the java files and copy them into your solr project.
  5. Update your solr.config and schema files.  Sorry I don’t have the exact lines (not at work) but its pretty obvious what lines are local solr related. <edit: read below>
  6. Update the drupal code to send the extra fields (I’ll try to find the exact ones later) .
  7. You’re done!

The only gotcha I found, resulting in a few lost hairs and an increase in blood pressure, was a funny error concerning the comments field.  The error I received was a integer conversion error, which I eventually found out was the number of comments being blank.  Just make sure you adjust your apachesolr.module file to set comments to zero when it is null.

I’ll try to get the drupal developers to support local solr so we can have some official code for you to use.

That’s it for now!

<update>

As suggested I’ll post this on the Drupal website, but for anyone interested the updates to the solr.config and scheme files:

::schema.xml

<field name=”lat” type=”sdouble” indexed=”true” stored=”true”/>
<field name=”lng” type=”sdouble” indexed=”true” stored=”true”/>
<field name=”geo_distance” type=”sdouble”/>
<dynamicField name=”_local*” type=”sdouble” indexed=”true” stored=”true”/>

::solr.config

line 177

<searchComponent name=”localsolr”     class=”com.pjaol.search.solr.

component.LocalSolrQueryComponent” >
<str name=”latField”>lat</str>
<str name=”lngField”>lng</str>
</searchComponent>

<!– local lucene request handler –>
<requestHandler name=”geo” class=”org.apache.solr.handler.component.SearchHandler”>
<lst name=”defaults”>
<str name=”echoParams”>explicit</str>
</lst>
<arr name=”components”>
<str>localsolr</str>
<str>facet</str>
<str>mlt</str>
<str>highlight</str>
<str>debug</str>
</arr>
</requestHandler>

line 574
<searchComponent name=”localsolr”     class=”com.pjaol.search.solr.

component.LocalSolrQueryComponent” >
<str name=”latField”>lat</str>
<str name=”lngField”>lng</str>
</searchComponent>

<!– local lucene request handler –>
<requestHandler name=”geo” class=”org.apache.solr.handler.component.SearchHandler”>
<lst name=”defaults”>
<str name=”echoParams”>explicit</str>
</lst>
<arr name=”components”>
<str>localsolr</str>
<str>facet</str>
<str>mlt</str>
<str>highlight</str>
<str>debug</str>
</arr>
</requestHandler>

3 Comments »

  1. It’ll be pretty easy to get the Drupal developers on board with your plans ;-)

    Is this a bug in the apachesolr.module?
    “Just make sure you adjust your apachesolr.module file to set comments to zero when it is null.”

    If you can provide some more detailed instructions (like the missing fields you talked about, the schema.xml changes, and what version of ApacheSolr you’re using) it would speed things along.

    Please submit issues to the ApacheSolr issue queue for all bugs and feature requests. It’s the fastest way to get them acted upon.
    http://drupal.org/project/issues/apachesolr

    Cheers,

    Robert

    Comment by Robert Douglass — December 14, 2008 @ 11:58 pm

  2. Thanks Robert, I created a feature request and hope to see some feedback soon.

    http://drupal.org/node/347428

    Comment by jarchowk — December 15, 2008 @ 9:47 pm

  3. [...] SOLR, Drupal, and GEO Spatial Results « Kurt Jarchow [...]

    Pingback by LizR.Net | Web Resource and Educations — December 16, 2008 @ 7:32 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Bad Behavior has blocked 107 access attempts in the last 7 days.