0

我在我的 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]。它似乎没有合适的“可搜索属性”(通常是简单的类型,如字符串、日期、数字等)、“可搜索引用”(通常是另一个域类)或“可搜索组件”(通常是另一个定义为组件的域类,使用“嵌入式”声明)。它是用'def'定义的派生属性(没有等效字段的getter方法)吗?尝试使用更具体的返回类型定义它

我的问题:是否可以在 grails 中使 dateCreated 和/或 lastUpdated 属性可搜索?如果可能,如何做到这一点?

谢谢。


编辑

如果我要在我的 config.groovy 中定义一个自定义转换器,如下所示:

地图 compassSettings = ['compass.converter. funkyConverter.type':'com.acme.compass.converter.FunkyConverter']

那么 FunkyConverter 类中定义了什么?

4

1 回答 1

1

Searchable 0.6 版附带的指南针版本(任何可能的早期版本)在其中包含一些用于 org.joda.time.DateTime 类的特殊情况代码(在类 org.compass.core.converter.DefaultConverterLookup 中)。我不能直接说它是否有效,但它看起来会尝试自动使用 Compass 中包含的 org.compass.core.converter.extended.DataTimeConverter 用于 joda DateTime 类。

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 )

于 2011-07-25T16:24:03.117 回答