OrderBy current date then by date

69 views
Skip to first unread message

Louis Haußknecht

unread,
Jun 19, 2013, 4:42:46 PM6/19/13
to rav...@googlegroups.com
Hi guys,

this is a rare case where a customer wants to see all deliveries in a list but with special order. He want's to see deliveries of the current day first, then all other deliveries (can be from the past or future).

In sql I woul'd do an order by as follows:
(pseudo code)

order by case 
when delivery_date = getDate() then 0 
else 1
end

In Raven I tried the same, but got an exception:

Are you trying to do computation during the query?
RavenDB doesn't allow computation during the query, computation is only allowed during index. Consider moving the operation to an index.


Can anybody suggest a way to write an index or to write a query for that?


Mircea Chirea

unread,
Jun 19, 2013, 4:51:58 PM6/19/13
to rav...@googlegroups.com
Why don't you load for the current day, then for all other dates, and merge the results client side?

Louis Haußknecht

unread,
Jun 19, 2013, 4:57:55 PM6/19/13
to rav...@googlegroups.com
I thought about that, but my query involves paging and I'm very happy to do all paging stuff with raven natively :)

Matt Johnson

unread,
Jun 19, 2013, 7:36:44 PM6/19/13
to rav...@googlegroups.com
You could have some other boolean property such as IsCurrentDay.  You would order by that first, then whatever you wanted as your secondary sort criteria.

But you would also need a task that runs at midnight every night to update the boolean.  This could be in your own application code, or you could write a custom bundle to do this.

Actually, now that I think about it, you could use the ClockDocs bundle I wrote to do it.  It's sitting in the Raven.Contrib project still.  But search this group for "ClockDocs" and read the feedback.  I haven't done a lot with it since then, and there was some concern about the stress that it could put on the server.  You should take that into consideration.
Reply all
Reply to author
Forward
0 new messages