Updating the Grails Solr Plugin

A few months back I was working on a Grails & Solr project – so it was a prime opportunity to answer my call to action (see the Solr plugin section of ‘Using Lucene in Grails’) and upgrade the Solr plugin to 3.5.0.
This was done in two phases, the first was to update the SolrJ client as required by the project and then once the project was completed to update the bundled Solr server with the aim of contributing the update back.

TLDR: Grails Solr Plugin using 3.5.0 3.6.0 available from https://github.com/rbramley/grails-solr-plugin pending https://github.com/mbrevoort/grails-solr-plugin/pull/2

Phase one: SolrJ

I started by upgrading the plugin from Grails 1.3.4 to 2.0.0 – other than application.properties, this affected the DataSource.groovy file with the switch from hsqldb to h2.

The next step was to remove the bundled SolrJ jar + dependencies from lib and move to using Ivy dependency management by adding a BuildConfig.groovy file with the following dependency for SolrJ:
compile ('org.apache.solr:solr-solrj:3.5.0') {}

Upon running the tests I hit a few failures, I fixed up a unit test assertion in SolrUtilTests.groovy by coercing a return value to a String and changing the expected value from a GStringImpl to a String. The integration tests weren’t passing as the Start Solr script wasn’t working – it wasn’t on the critical path for the project so that was deferred to phase 2.

Phase two: Bundled Solr

1. Failing integration tests

The starting point of phase 2 was to get the integration tests working so that changes going forward were from a known good starting point.

As mentioned beforehand, the Start Solr (grails start-solr) script wasn’t working so that was the first port of call. The failure was caused by a missing log directory from ~/.grails/<project name>/solr-home which was easily rectified with an addition to the script:

def solrLogDir = "${solrHome}/logs"
if(! new File(solrLogDir)?.exists()) {
  Ant.mkdir(dir: "${solrLogDir}")

Alright, so now the integration tests can run, but they’re still working against Solr 1.4 – time to get on with the version upgrade.

2. Upgrading solr-local to 3.5.0

I followed the existing plugin pattern of an embedded war file and jars for speed – though it might be nicer to move this to dependencies managed from the start script.

This was simply a case of unpacking Solr 3.5.0 over the top and merging / fixing up the configuration and schema.

3. Spatial

This error message: Expected identifier at pos 87
required a change to use the Solr 3.1+ hsin syntax.

4. Assertion errors

In two cases the expected field value in the DomainMethodTests was returning an array rather than the SolrId – the quick fix was to use the first element.

Tests passing = upgrade completed so it was committed and pushed to https://github.com/rbramley/grails-solr-plugin before sending a pull request.


If you take it from my GitHub repo, you can either download the packaged plugin or grab the full source and package the plugin; the plugin zip can then be installed into your local project (this would need doing on each environment e.g. CI).
Alternatively you can use a local plugin repo (see the Plugins chapter of the Grails user guide) or lobby for the pull request to be merged in and the updated plugin to be released!


The upgrade was completed and a pull request (https://github.com/mbrevoort/grails-solr-plugin/pull/2) sent upstream to Mike Brevoort, but sadly he hasn’t had the time to merge this in and meanwhile Solr 3.6.0 was released… So I’ve upgraded it again – all the tests pass but be aware that I haven’t had the chance to test it more extensively.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s