Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Query builder - search for child components

Avatar

Level 2

Hi,

I'm looking to retrieve child nodes of a parent node based on their resourcetype. So for exampe, i have a tabs component on my page and i want to retrieve the child accordions out of the tabs. I actually have this query:

type=nt:unstructured
path=/content/path/to/my/page
p.limit=-1
p.hits=full
1_property=sling:resourceType
1_property.value=qt/components/content/tabs
p.nodedepth=4

 

This query returns the tabs and their child components (thanks to nodedepth). But the best for me would be to refine the query to only get a collection of accordions. I don't need the tabs, I only need the accordions located into the tabs. Is there a way to do this?

Thanks for the help!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @dartoism-inetum,

We can make use of JCR-SQL2 query for this use case. 

Assumption : Content structure is tabs -> items[1..n]responsivegrid -> accordion. 

If your content structure is deviating from the assumption, please share the same. We can amend the query accordingly. 

select c.* from [nt:unstructured] as a 
inner join [nt:unstructured] as b on ischildnode(b,a) 
inner join [nt:unstructured] as c on ischildnode(c, b)
where isdescendantnode(a, '/content/demo') 
and a.[sling:resourceType]='demoproject/components/content/tabs'
and b.[sling:resourceType]='wcm/foundation/components/responsivegrid'
and c.[sling:resourceType]='demoproject/components/content/accordion'

Vijayalakshmi_S_0-1634911237397.png

 

 

View solution in original post

3 Replies

Avatar

Level 2

Hi @Bhuwan_B,

 

Thank you for your quick reply. I might be wrong but i don't think this will do the trick. It looks more about path filtering. I would like to have the child nodes of a parent node based on child's resourceType value. Something like this (which is wrong of course):

type=nt:unstructured
path=/content/path/to/my/page
p.limit=-1
p.hits=full
1_property=sling:resourceType
1_property.value=qt/components/content/accordion

1_with_parent_property=sling:resourceType
1_with_parent_property.value=qt/components/content/tabs

I'm not very familiar with such queries. if you think it can be done can you propose something based on the above code? Thanks!

Avatar

Correct answer by
Community Advisor

Hi @dartoism-inetum,

We can make use of JCR-SQL2 query for this use case. 

Assumption : Content structure is tabs -> items[1..n]responsivegrid -> accordion. 

If your content structure is deviating from the assumption, please share the same. We can amend the query accordingly. 

select c.* from [nt:unstructured] as a 
inner join [nt:unstructured] as b on ischildnode(b,a) 
inner join [nt:unstructured] as c on ischildnode(c, b)
where isdescendantnode(a, '/content/demo') 
and a.[sling:resourceType]='demoproject/components/content/tabs'
and b.[sling:resourceType]='wcm/foundation/components/responsivegrid'
and c.[sling:resourceType]='demoproject/components/content/accordion'

Vijayalakshmi_S_0-1634911237397.png