I am using Compass to make queries on data inside in memory data structure. It works fine for searching String and enum values, now I want to search dates.
Search criteria are annotated by @SearchRestriction
annotation. Example about someDate:
@SearchRestriction(path="fooBar.someDate" type = SearchRestrictionType.EQUAL)
String someDate;
At searchable data SomeDate is annotated like the following:
@SearchableProperty
Date someDate;
SomeDate
inside the searchable data is generated with new Date();
) and query String is given as 20120802
.
Situation on debugger: This code generates queries like this:
someDate:20120802
Here someDate
is the name of the field I am looking for and 20120802
is a date in order yyyyMMdd.
Problem: No results is returned, when this query is run. I get an empty list. The Date in query is the same as in the Date object.
What is wrong??
Is this wrong way to search Date
s with Compass? I can find only range queries about Date, but a search with exact Date or part of exact Date I cannot find.
You need to specify the format for Searchable property [Date]
@SearchableProperty(format = "yyyyMMdd")
To some extent, it relates to Grails: Lucene, Compass Query Builder and date ranges