Find first level child using query | Community
Skip to main content
New Participant
October 16, 2015
Solved

Find first level child using query

  • October 16, 2015
  • 4 replies
  • 4868 views

Hi

I am trying to find the child pages for the content path provided, I am using the below parameter to find the pages :

path=/content/geometrixx/en/toolbar type=cq:Page orderby=@jcr:content/cq:lastModified

This giving me all pages below toolbar also the childs of child like

But i want only at first level and not above account, Any idea how to add criteria in query debugger to find only child page of the path selected.

Thanks

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

If you are not required to use a query, I would use the API and use somthing like this; it is much faster than a query.

Page p = ... Iterator<Page> iter = p.listChildren();

(see https://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/Page.html#listChildren%28com.day.cq.commons.Filter%29)

4 replies

New Participant
August 3, 2021

You can use path.flat=true in your query string to get only the direct children.

  • path : This is used to search under a  particular hierarchy only.
    • path.self=true : If true searches the subtree including the main node given in path,  if false searches the subtree only.
    • path.exact=true : If true exact path is matched, if false all descendants are included.
    • path.flat=true If true searches only the direct children .
joerghoh
joerghohAccepted solution
Employee
October 16, 2015

If you are not required to use a query, I would use the API and use somthing like this; it is much faster than a query.

Page p = ... Iterator<Page> iter = p.listChildren();

(see https://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/Page.html#listChildren%28com.day.cq.commons.Filter%29)

vdhim23Author
New Participant
October 16, 2015

Jörg Hoh wrote...

If you are not required to use a query, I would use the API and use somthing like this; it is much faster than a query.

  1. Page p = ...
  2. Iterator<Page> iter = p.listChildren();

(see https://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/Page.html#listChildren%28com.day.cq.commons.Filter%29)

 

 

 

Thanks Jorg, I want to use query not because only to list children, I need to some other operation to apply on the resultset, like i want to get the child pages in sorted order & may be some more filters can be added.  I have made changes in my original post, please suggest if you can provide me the parameters to be use in query debugger.

joerghoh
Employee
October 16, 2015

Hi

First of all, there is variant of the listChildren() method available, where you can specify a filter. But this method does not support ordering, in that case you need to do it yourself.
I am not really familiar with the querybuilder,  but if you use JCR SQL2 directly, you could use something like this:

SELECT * FROM [cq:Page] AS s WHERE ISCHILDNODE(s,'/content/geometrixx/en/toolbar') order by [jcr:content/cq:lastModified]

kind regards,
Jörg