Reputation: 3
I need to search on the basis of "Last month", "Last week", "Last 3 months", "Last year".. Am using the code as below.
map.put("1_relativedaterange.property", "date");
map.put("1_relativedaterange.lowerBound", "-1M");
Respectively putting -7d, -3M, -1y.
These work for last date ranges. I expect that with these criteria it should not search if the dates are next month, next week or next year. But it is searching that as well, which should not. Anybody please point out what I am doing wrong here?
Thanks.
Upvotes: 0
Views: 5253
Reputation: 9281
When you specfify the lowerBound, the resulting Xpath query that is generated is
/jcr:root/content/geometrixx/en//element(*, cq:Page)
[
(@jcr:content/cq:lastModified > xs:dateTime('2014-05-30T02:18:50.479Z'))
]
which means it would fetch all the items which has date value greater than the above.
You can specify an upperBound value as 0, indicating now. This would return only those results that do not exceed the current date, apart from satisfying your other criteria.
map.put("1_relativedaterange.property", "date");
map.put("1_relativedaterange.lowerBound", "-1M");
map.put("1_relativedaterange.upperBound", "0");
and the corresponding XPath query that gets generated is
/jcr:root/content/geometrixx/en//element(*, cq:Page)
[
(@jcr:content/cq:lastModified > xs:dateTime('2014-05-30T02:25:21.026Z')
and @jcr:content/cq:lastModified < xs:dateTime('2014-06-29T02:25:21.026Z'))
]
The querydebug console(/libs/cq/search/content/querydebug.html
) might come in handy when you need to debug your queries.
For additional info on relative date range predicate evaluator, refer the docs.
Upvotes: 1