Last updated by khausam
1 year ago
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 supportsMap<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.my.converters.MyFunkyConverter',
'compass.converter.funkyConverter.registerClass': 'com.acme.my.special.classes.MyCoolDateTime'
]Spring beans
If you define a Spring bean inresources.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, egimport com.acme.compass.converter.MyHtmlConverter beans = { htmlConverter(MyHtmlConverter) { context = someContext includeMeta = true } }
Using Converters
Converters are defined in the class mapping, at either the class levelclass Book {
static searchable = {
converter 'bookConverter'
}
String title
}class Book {
static searchable = {
title converter: 'bookTitleConverter'
}
String title
}