Complex Sorting - Date Ranges
We have a scenario where we have a items with dates and date ranges, think of them as events.
- A) Feb 1 - Feb 28 (End Date: Feb 28)
- B) Feb 27 (End Date: Feb 27)
- C) Feb 15 - March 15 (End Date: March 15)
- D) Feb 10 - March 30 (End Date: March 30)
- E) Jan - March 31
Sorting by "end date" gives us the following order: B,A,C,D, E
With today being Feb 23, the true order should be. A, C, D, E, B
Basically, if an event is currently happening we should be sorting by todays date, not the end date of the shows. End date should be the secondary sort.
I think we need to generate an on-the-fly field that returns in the current date if the show is active and the end date if the show is not yet active. In Sitecore the items have a start and end date and but aren't reindexed everyday for generate a "todays date" as a server side computed field. I suppose we could write an agent to do so, but I'm wondering if we could solve this problem in Coveo. :)
Any thoughts on a solution for this?
I'm aware of query functions: https://developers.coveo.com/display/public/SearchREST/Query+Function
But that looks pretty-pretty-dark! http://www.partow.net/programming/exprtk/index.html
This is a very good question. Here's my attempt at it. Let's assume some things:
- Events that are finished aren't part of the search results (query filter @enddate>=today)
- Events that are one day long only have the same start date as the end date (may be done with PostIemProcessingPipeline processor)
I would use the
sortCriteria property of the JS UI
queryBuilder and set 2 sort fields as supported since the June 2015 release (see sortCriteria) like this:
args.queryBuilder.sortCriteria = '@startdate ascending, @enddate ascending';
So for any 2 events with the same start date, the one ending earliest will be first.
Tell me if this works for you,