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>

November 13, 2008

From .Net to Php, Amazon EC2 and Solr

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

I’ve been off a few days because moving houses, but I’ve been busy at work.  I’ve taken what I’ve learned from my last post, and starting getting my hands dirty.

I’ve been soley developing in Microsoft products since I started developing, so this transition has been a slow one for me.   I’ll share my pains in the hopes I can help someone else.

Installing the LAMP stack on Amazon can be a breeze if you do it right.  Read these instructions for a quick setup with a VNC access.  I’ll briefly outline the steps from base install to solr:

  • Do yourself a favour and download the Firefox extention
  • When you create an instance of a server you have a long list of pre-installed packages to choose from- find the Hardy Ubuntu AMI
  • Install the LAMP stack using the command prompt (see link above) it also installed PHPMySql
  • For the newest Java install I used the Add Program options in the GUI, real simple
  • I downloaded solr from the site and followed the instructions on the site, worked like a charm

My path was riddled with many different dead ends when installing this, but in the end it could have been a 1 hour job.  My main stumbling block was getting vncserver to run with the amazon getting-started AMI builds.  Essentially I had to install everything manually, which is NO fun.

Next steps: trying to get solr to run as a webservice so I can access it internally.  Right now it is behind the 8983 port and I can’t access it from the web.  I’ll let you know how I get on later, and hopefully I’ll have my proof of concept all completed.

Powered by WordPress

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