Expand my Community achievements bar.

Issue in Search using DateRangePredicate for fetching results having - enddate >= now(currentdate)

Avatar

Level 3

Hi All,

In one of our functionality we need to search for event pages only with in a specific date range. forexample if we have events starts from 12May and end date as 15 May then this event should only be visible till 15 May. 

Two issues that we are facing :

1. query is executing with > and not with >=

2. query is executing with AND claues but we need OR between two dates.

We have used search parameters using Querybuilder for search execution as below : 

// here DateRangeParameter extends com.hm.glow.services.search.Parameter

searchParameters = new SearchParameters(path, session); String currentDate = getCurrentDate(); DateRangeParameter eventStartDate = new DateRangeParameter(EVENT_START_DATE); eventStartDate.setLowerBound(currentDate); searchParameters.addParameter(eventStartDate); //ISSUE : we need to  have >= instaed of > and between event start and event end date because currently it works for > condition. DateRangeParameter eventEndDate = new DateRangeParameter(EVENT_END_DATE); eventEndDate.setLowerBound(currentDate); searchParameters.addParameter(eventEndDate); searchParameters.setOffset(NumberUtils.toInt(getParameter(SearchConstants.OFFSET_PARAM_NAME))); searchParameters.setLimit(NumberUtils.toInt(getParameter(SearchConstants.RESULTS_PARAM_NAME))); searchParameters.setOrderBy(new OrderBy(START_DATE_PROPERTY, SortOrder.ASC));

The search query that executed at back-end with this line of code is below :

xpath query: /jcr:root/content/hmgroup/groupsite/en/media/calendar//*[(jcr:content/event-time/@startDate < xs:dateTime('2016-05-12T11:44:54.895+05:30')) and (jcr:content/event-time/@endDate > xs:dateTime('2016-05-12T11:44:54.895+05:30')) and ((jcr:content/@cq:template = '/apps/hmgroup/templates/calendar-event'))] order by jcr:content/event-time/@startDate

 

Expected Query:

xpath query: /jcr:root/content/hmgroup/groupsite/en/media/calendar//*[(jcr:content/event-time/@startDate =< xs:dateTime('2016-05-12T11:44:54.895+05:30')) or (jcr:content/event-time/@endDate >= xs:dateTime('2016-05-12T11:44:54.895+05:30')) and ((jcr:content/@cq:template = '/apps/hmgroup/templates/calendar-event'))] order by jcr:content/event-time/@startDate

Could anyone please suggest how can we make above query to get the expected result.

Thanks,

Radhika

0 Replies