Converters
In order to transform your objects and their properties into
searchable text, and from data stored in the index back into objects,
Compass has the notion of _converters_.
Compass acts as a registry of converters, each identified by name.
Compass includes many converters itself, some responsible for
converting entire class instances and some for individual properties.
Additionally the plugin includes a custom converter itself which
supports
Map<String, String> class property types, since Grails
supports this as a persistent class property type.
Defining Converter implementations
You can define a converter with Compass settings and (since 0.5.1) as
Spring beans.
Compass settings
The
Compass settings
can either be defined in the plugin's
configuration or in a
native Compass configuration file.
In the plugin's config you might do:
Map compassSettings = [
'compass.converter. funkyConverter.type': 'com.acme.compass.converter.FunkyConverter'
]which registers a converter called
"funkyConverter"@.See the Compass settings for the complete range of options.Spring beans
If you define a Spring bean in @resources.xml or
resources.groovy that is an instance of
org.compass.core.converter.Converter then it wil be
automatically registered with Compass using the Spring bean name as it's name.
This allows you to inject your analyzer with other Spring beans and
configuration, eg
import com.acme.compass.converter.MyHtmlConverter
beans = {
htmlConverter(MyHtmlConverter) {
context = someContext
includeMeta = true
}
}defines a converter called @"htmlConverter"@.
Using Converters
Converters are defined in the class mapping, either at either at the class level
class Book {
static searchable = {
converter 'bookConverter'
}
String title
}and/or at the property level
class Book {
static searchable = {
title converter: 'bookTitleConverter'
}
String title
}Note you can also use native Compass
XML or
annotations to map with custom converters.