Grails: Lucene, Compass Query Builder and date ranges

大憨熊 提交于 2019-12-02 12:53:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5809428/grails-lucene-compass-query-builder-and-date-ranges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!