使 joda.DateTime 成为 grails 中的可搜索属性

发布于 2024-10-14 20:21:20 字数 973 浏览 4 评论 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]。看来没有合适的 “可搜索属性”(通常很简单 字符串、日期、数字等类型, 等),“可搜索参考”(通常 另一个域类)或“可搜索” 组件'(通常是另一个域 类定义为组件,使用 “嵌入”声明)。是不是一个 派生属性(带有 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈下烟灰 2024-10-21 20:21:20

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 中实例化。

compassSettings = [
    "compass.converter.jodatime.type": "net.streamrecorder.web.converter.LocalTimeConverter",
    "compass.converter.jodatime.registerClass": "org.joda.time.LocalTime"
]

请注意,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.

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 )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文