Reputation: 7926
I am using the joda time library in my grails project. I've installed the searchable plugin. I have a few domains but the most important now :
import org.joda.time.DateTime
class Entry {
static searchable = {
except = ['id', 'version']
spellCheck "include"
tags component: true
title boost: 2.0
dateCreated boost: 2.0
}
String title
String content
DateTime dateCreated
DateTime lastUpdated
}
But on initialization I encounter the following error:
Unable to map [Entry.dateCreated]. It does not appear to a suitable 'searchable property' (normally simple types like Strings, Dates, Numbers, etc), 'searchable reference' (normally another domain class) or 'searchable component' (normally another domain class defined as a component, using the 'embedded' declaration). Is it a derived property (a getter method with no equivalent field) defined with 'def'? Try defining it with a more specific return type
My question: Is it possible to make the dateCreated and/or lastUpdated properties searchable in grails? If possible, how can this be done?
Thanks.
If I was to define a custom converter in my config.groovy like so:
Map compassSettings = [ 'compass.converter. funkyConverter.type':'com.acme.compass.converter.FunkyConverter']
What is then defined in the FunkyConverter class?
Upvotes: 0
Views: 688
Reputation: 172
The version of compass that came with version 0.6 of Searchable (any maybe earlier versions) had some special case code in it (in class org.compass.core.converter.DefaultConverterLookup) for the org.joda.time.DateTime class. I can't speak directly to whether it works or not, but it looked like it would try to automatically make use of org.compass.core.converter.extended.DataTimeConverter included in Compass for the joda DateTime class.
However, for joda LocalDate and LocalTime classes, there was no built-in support. A recent bug fix to Searchable version 0.6.1 ( http://jira.grails.org/browse/GPSEARCHABLE-28 ) along with the use of the registerClass configuration in Searchable.groovy shown below has fixed my "It does not appear to a suitable 'searchable property'..." problem that was occurring at application startup while domain objects were being instantiated in Bootstrap.groovy.
compassSettings = [
"compass.converter.jodatime.type": "net.streamrecorder.web.converter.LocalTimeConverter",
"compass.converter.jodatime.registerClass": "org.joda.time.LocalTime"
]
Note that net.streamrecorder.web.converter.LocalTimeConverter is my own creation. I modeled it after org.compass.core.converter.extended.DataTimeConverter. There is also a converter for LocalDate in this diff referenced from the GPSEARCHABLE-28 ticket: ( http://jira.grails.org/secure/attachment/15729/0001-Nasty-fixes-and-workarounds-for-adding-custom-compas.patch ) And of course, you still need to specify your converter for your domain member variable in your domain class as described here: ( http://grails.org/Searchable+Plugin+-+Converters )
Upvotes: 1