Grails: Lucene, Compass Query Builder and Date Ranges

I have a search plugin that works with my grails project. I have indexing 4 different tables at work. Unfortunately, each table has a date field, which is called differently. Some of them are called createdAt, some of them are namedOn, etc.

As part of my search, I need to get items that are within a certain date range from these fields. Is there any way to do this? I saw one specific instance in the documentation for the plugin, but it does not account for different field names, as I should deal with.

+1
source share
1 answer

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

So, suppose you have a class with the property "publishedOn", but you want this property to be searchable by both "publishOn" 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 want it to be searchable as "createdAt", just leave the first entry available for search.

+3
source

All Articles