我在我的 grails 项目中使用 joda 时间库。
我已经安装了可搜索插件。
我有几个域,但现在最重要的是:
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
}
但在初始化时我遇到以下错误:
无法映射 [Entry.dateCreated]。看来没有合适的
“可搜索属性”(通常很简单
字符串、日期、数字等类型,
等),“可搜索参考”(通常
另一个域类)或“可搜索”
组件'(通常是另一个域
类定义为组件,使用
“嵌入”声明)。是不是一个
派生属性(带有 getter 方法
没有等效字段)定义为
‘定义’?尝试用 more 来定义它
具体返回类型
我的问题:
是否可以使 dateCreated 和/或 lastUpdated 属性在 grails 中可搜索?
如果可以的话,如何做到这一点?
谢谢。
EDIT
如果我要在 config.groovy 中定义一个自定义转换器,如下所示:
地图指南针设置 = [
'指南针转换器。 funkyConverter.type':'com.acme.compass.converter.FunkyConverter']
那么 FunkyConverter 类中定义了什么?
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.
EDIT
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?
发布评论
评论(1)
Searchable 0.6 版本(任何可能的早期版本)附带的指南针版本中有一些针对 org.joda.time.DateTime 类的特殊情况代码(在类 org.compass.core.converter.DefaultConverterLookup 中)。我不能直接谈论它是否有效,但看起来它会尝试自动使用 Compass 中包含的 org.compass.core.converter.extended.DataTimeConverter 来实现 joda DateTime 类。
但是,对于 joda LocalDate 和 LocalTime 类,没有内置支持。最近对可搜索版本 0.6.1 进行了错误修复 ( http://jira.grails.org/browse/ GPSEARCHABLE-28 )以及在 Searchable.groovy 中使用 registerClass 配置(如下所示)修复了我的“它似乎没有合适的‘可搜索属性’...”问题,该问题在应用程序启动时发生,而域对象正在 Bootstrap.groovy 中实例化。
请注意,net.streamrecorder.web.converter.LocalTimeConverter 是我自己的创建。我按照 org.compass.core.converter.extended.DataTimeConverter 建模。此差异中还有一个从 GPSEARCHABLE-28 票证引用的 LocalDate 转换器:( http://jira.grails.org/secure/attachment/15729/0001-Nasty-fixes-and-workarounds-for-adding-custom-compas。 patch )当然,您仍然需要为域类中的域成员变量指定转换器,如下所述:( http://grails.org/Searchable+Plugin+-+Converters )
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.
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 )