orderby nodename but treat as an integer | Community
Skip to main content
New Participant
October 16, 2015
Solved

orderby nodename but treat as an integer

  • October 16, 2015
  • 2 replies
  • 849 views

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
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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

2 replies

smacdonald2008
New Participant
October 16, 2015

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). 

joerghoh
joerghohAccepted solution
Employee
October 16, 2015

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