Grails:Lucene,Compass查询生成器和日期范围 [英] Grails: Lucene, Compass Query Builder and date ranges

查看:142
本文介绍了Grails:Lucene,Compass查询生成器和日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可搜索的插件与我的grails项目一起工作。我有它在工作索引4个不同的表。不幸的是,每个表都有一个名称不同的日期字段。有些被命名为createdAt,有些被命名为publishedOn等等。



在我的搜索范围内,我需要获得特定日期范围内的项目。有没有办法做到这一点?我已经在插件的文档中看到了一个特定的实例,但它没有考虑到我必须处理的不同字段名称。

解决方案

所以,假设你有一个属于你的域的类,你可以配置你的域类来覆盖或为不同名称的属性提供额外的Lucene索引条目。类与'publishedOn'属性,但您希望该属性可以作为'publishedOn'和'createdAt'进行搜索。您可以执行以下操作:

  class ADomainClass {
发布日期在

static searchable = {
'publishedOn'format:'yyyyMMdd'
'publishedOn'name:'createdAt',format'yyyyMMdd'
}
}

如果您只希望将其作为'createdAt'进行搜索,那么只需省略第一个可搜索条目即可。


I have the searchable plugin working with my grails project. I have it indexing 4 different tables at work. Unfortunately, each table has a date field that is named differently. Some are named createdAt, some named publishedOn, etc...

Within my search, I need to get items that are within a specific date range out of those fields. Is there a way to do this? I've seen one specific instance in the documentation for the plugin, but it doesn't take into account different field names like I have to deal with.

解决方案

you can configure your domain classes to override or provide additional Lucene index entries for a property under different names.

So, suppose that you have a class with a 'publishedOn' property, but you want that property to be searchable as both 'publishedOn' and 'createdAt'. You would do something like the following:

class ADomainClass {
    Date publishedOn

    static searchable = {
       'publishedOn' format:'yyyyMMdd'
       'publishedOn' name: 'createdAt', format 'yyyyMMdd'
    }
}

If you only want it to be searchable as 'createdAt', then just leave out the first 'searchable' entry.

这篇关于Grails:Lucene,Compass查询生成器和日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆