OrderBy file structure | Community
Skip to main content
manikanthar1295
Level 5
December 2, 2022
Solved

OrderBy file structure

  • December 2, 2022
  • 2 replies
  • 1522 views

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

 

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

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.

2 replies

arunpatidar
Community Advisor
Community Advisor
December 2, 2022

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
Arun Patidar
manikanthar1295
Level 5
December 2, 2022

Hi Arun,

 

Thanks for your quick reply

 

Below is screen shot for reference

 

 

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

 

I tried Query debugger

 

 

Its not giving as expected.

 

Need your help here

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
December 3, 2022

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.

Lokesh_Vajrala
Community Advisor
Community Advisor
December 2, 2022

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.

manikanthar1295
Level 5
December 2, 2022

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

 

 

 

 

Lokesh_Vajrala
Community Advisor
Community Advisor
December 2, 2022

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?