Monday 23 June 2008

Stemming and the Grails Searchable Plugin

The standard analyizer that compass defaults to doesn't support stemming. The closest you can get is to use wild card searches. If you want to go the whole hog, here's what you have to do...

1. Open /grails-app/conf/SearchableConfiguration.groovy and replace

Map compassSettings = [:]

with

Map compassSettings = ['compass.engine.analyzer.default.type': 'snowball',
'compass.engine.analyzer.default.name': 'English',
'compass.engine.analyzer.search.type': 'snowball',
'compass.engine.analyzer.search.name': 'English']


2. Use queryString(<luceneQuery>, <params>) in your search service rather than the 'term' or 'wildcard' commands. e.g.

queryString("name:${match}", [boost: 10])

You're supposed to be able to specify the analyzer to use as a parameter to queryString, but I haven't tried this yet, as for my app I only need to support English.

3. Don't even bother trying to get stemming working if you use term, the plugin simply ignores any analyzer settings and constructs the StandardAnalyser from a hard coded class name. I raised a feature request for this, but it was bounced because Maurice thinks we should be forced to write lucene queries by hand. Never mind that the point of whole point of compass was to isolate your from the underlying search engine technology, or that DSLs are a much nicer mechanism for query creation than string manipulation. Ho Hum.

No comments: