I'm having difficulties in being able to order/sort on names and dates with a DynamicNodeList.
A bit of background:
Search results page. Takes a user query, uses UmbracoExamine to search the content and any PDF documents within media. This works great, and returns results based on relevance.
A user has the option to sort the results based on the published date or the title. UmbracoExamine.PDFdoesn't store any title/date information for documents, so this isn't possible with the searchResults object that is returned after the search. So, I've pushed the results into a DynamicNodeList object. From here, I'm trying to sort, before looping through (with a foreach) to display the results on the page.
I've tried a few things:
umbNodeList.OrderBy(x => x.GetProperty("title").Value); (we have a separate title field along with the default "name") and umbNodeList.OrderBy("title desc");, but neither of these are working. The first is just ignored (it seems), and the second suggests that there's no definition for the OrderBy function like that.
Would anyone have any tips on how to resolve this?
Thanks for the response. I've just tried it with that, and while I'm not getting any errors, it isn't sorting the results either by the looks of things - either on the page or in the list itself?
It's just what seemed logical, to get a list of DynamicNode objects from searching around. A more hacky solution I'm implementing at the moment as a work-around is pulling out the title/create date information into separate lists to just sort on those properties, before creating a new node list from the sorted data.
Topic author was deleted
Sorting DynamicNodeList (after UmbracoExamine search)
Hi,
I'm having difficulties in being able to order/sort on names and dates with a
DynamicNodeList
.A bit of background: Search results page. Takes a user query, uses UmbracoExamine to search the content and any PDF documents within media. This works great, and returns results based on relevance.
A user has the option to sort the results based on the published date or the title.
UmbracoExamine.PDF
doesn't store any title/date information for documents, so this isn't possible with thesearchResults
object that is returned after the search. So, I've pushed the results into aDynamicNodeList
object. From here, I'm trying to sort, before looping through (with aforeach
) to display the results on the page.I've tried a few things:
umbNodeList.OrderBy(x => x.GetProperty("title").Value);
(we have a separate title field along with the default "name") andumbNodeList.OrderBy("title desc");
, but neither of these are working. The first is just ignored (it seems), and the second suggests that there's no definition for theOrderBy
function like that.Would anyone have any tips on how to resolve this?
Hi Ed,
Try like that : umbNodeList.Items.OrderBy(x => x.GetProperty("title").Value)
Comment author was deleted
Hi Alex,
Thanks for the response. I've just tried it with that, and while I'm not getting any errors, it isn't sorting the results either by the looks of things - either on the page or in the list itself?
Can you explain why you push the data into a DynamicNodeList? It's a rather old legacy class which was used in Razor in Umbraco 4.7.
Jeroen
Comment author was deleted
It's just what seemed logical, to get a list of
DynamicNode
objects from searching around. A more hacky solution I'm implementing at the moment as a work-around is pulling out the title/create date information into separate lists to just sort on those properties, before creating a new node list from the sorted data.is working on a reply...