Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

orderby nodename but treat as an integer

Avatar

Level 5

I'm storing news releases in cq:page nodes with name corresponding to the release ID--which are integers that increment by 1 with each new release created. I need to be able to sort these release by the release ID to do a variety of operation, in this case to get the highest numbered release. Unfortunately I can't rely on jcr:created for this because there are special cases where the highest numbered release will not correspond to the last created page (support for a legacy system). 

I've been experimenting with the query debugger to try to figure out how I would retrieve this, but when I sort on nodename, it orders results not as numbers, but strings, thus, I get results like "9000, 8200, 81320, 7000, 22000, 1700, 12000" Is there a way to cast my orderby property to an int? Or am I maybe going about this the wrong way?

type=cq:page path=/content/news orderby=nodename orderby.sort=desc
1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

IIRC you cannot cast in the "order by" statement. What you can do is to create an integer property "releaseID" and sort by this property. Then you should have a numerical comparison instead a string-based one.

kind regards,
Jörg

View solution in original post

2 Replies

Avatar

Level 10

Because the node name is a string - you cannot order it as if it's a numeric value:

http://www.day.com/specs/jcr/1.0/6.6.3.5_Ordering_Specifier.html

If you want to order these nodes using a numeric value- place a child node on the page of type nt:unstructured (you cannot place a custom numeric property on a page node).

Place a custom numeric property on the child node and order by this numeric prop.  Then you will have an order collection based on a numeric value.   (this is one way to do this). 

Avatar

Correct answer by
Employee Advisor

Hi,

IIRC you cannot cast in the "order by" statement. What you can do is to create an integer property "releaseID" and sort by this property. Then you should have a numerical comparison instead a string-based one.

kind regards,
Jörg