Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

OrderBy file structure

Avatar

Level 6

Hi Team,

 

Need some clarification on orderby in query builder  for pages.

 

I have parent page inside that i have 10 child pages 

 

If not specify any order in Query builder on which order sort will happen ??

 

If I want to sort on file structure which parameter i need to pass to Query builder.

 

Need your input here .

 

Thanks and Regards

Manikantha R

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

The order in the result set of a query will only be determined by the order by statement; and you cannot search for the "natural" order in which sibling nodes are ordered.

If you need to need to process the child nodes of a node in their natural order, do not search for the child nodes, but rather their parent; and then iterate the children of the parent node.

View solution in original post

7 Replies

Avatar

Community Advisor

Hi,

I think the order is node order in the tree.

what do you mean by file structure order?

If you want to sort with node type

path=/content/aemlab/oneweb/us
orderby=@jcr:primaryType
orderby.sort=desc
p.limit=-1

Avatar

Level 6

Hi Arun,

 

Thanks for your quick reply

 

Below is screen shot for reference

 

manikanthar1295_0-1669982090164.png

 

In we-retail site i need the order in highlighted way.

 

I tried Query debugger

 

manikanthar1295_1-1669982251947.png

 

Its not giving as expected.

 

Need your help here

Avatar

Correct answer by
Employee Advisor

The order in the result set of a query will only be determined by the order by statement; and you cannot search for the "natural" order in which sibling nodes are ordered.

If you need to need to process the child nodes of a node in their natural order, do not search for the child nodes, but rather their parent; and then iterate the children of the parent node.

Avatar

Level 4

Hi @manikanthar1295

PREVIEW
If you need to order, you have put the order by clause.

please refer querybuilder_cheatsheet

https://github.com/paulrohrbeck/aem-links/blob/master/querybuilder_cheatsheet.md

Following will sort by node path(tree) orderby = @jcr:path

Ex:

type=cq:Page
path=content/we-retail/us/en/experience
orderby=@jcr:path

But you can simply use navigational access (node.getNodes()) in case you want node order.

Thanks

Avatar

Level 6

When the orderby predicate is not specified in the query, the order of results returned is random, and the order in the JCR is not followed.

When you specify the orderby predicate without the sort order, the default ordering is ascending - asc.

Avatar

Level 6

Hi Lokesh

Thanks for quick reply

 

I have tried with below format

 

type=cq:Page
path=/content/we-retail/us/en/experience/
orderby=@jcr:path

 

what parameter we need to pass for orderyby to get in like below format

 

manikanthar1295_0-1669984238130.png

 

 

 

Avatar

Level 6

I think for this case you can simply use the page.listChildren() instead of running a query to get child pages, which will give you the order you wanted.

Is there a reason why you've to run a query to get the child pages as in the order of JCR?