Dynamic sorting in ContentQuery

Topics: Writing modules
Apr 10, 2013 at 10:34 AM
Edited Apr 10, 2013 at 12:12 PM
I'd like to have a ContentQuery sorted by an arbitrary expression (like it's possible with LINQ) but it seems that you can only specify a record property to use for sorting. Has anyone succeeded using a custom expression for OrderBy() or is this really not possible?

More specifically I'd like to sort search hits by relevance but also further alter the list of items returned by using ContentQuery. Since search hits are returned as ids here the content items should be queried by their id. Since there's no queryable equivalent of GetMany() available the only option I see here is to query on the id of a regular content part - I'm using CommonPartRecord. This produces an IN() clause in the SQL but this, unlike the IN() produced by GetMany() isn't keeping ordering (the latter on produces an IN() on ContentItemRecord.Id).

Due to the number of items LINQ to objects sorting is not an option. I know this is possible with IHqlQuery but the query is exposed from a service and I'd rather stick to ContentQuery. There were some discussions about using NHibernate's QueryOver what supports such expressions but I see no traces of it in the latest source.
Apr 11, 2013 at 4:17 AM
This is pretty much why the HQL APIs were added.
Apr 11, 2013 at 9:33 AM