Query builder - search for child components | Community
Skip to main content
October 22, 2021
Solved

Query builder - search for child components

  • October 22, 2021
  • 2 replies
  • 1681 views

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!

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 Vijayalakshmi_S

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'

 

 

2 replies

October 22, 2021

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!

Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
October 22, 2021

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'