JCR Query - Search for two components under a parent | Community
Skip to main content
Singaiah_Chintalapudi
Level 7
January 16, 2019

JCR Query - Search for two components under a parent

  • January 16, 2019
  • 1 reply
  • 17272 views

Hi,

I am trying to find the query to extract all the pages which has two components in it. I wrote the query to extract a single component but having trouble to write the query to pull the pages which has both components.

Any help would be appreciated.

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Gaurav-Behl
Level 10
January 17, 2019

Do you plan to use this query in source code or run it via /crx/de? Based on the use case, it would be easy to figure out if you need SQL2, XPATH or you could use QB etc.

How deep in the hierarchy level these components are configured in node structure?  It's easy to look at just 2 node levels but if you want to go deep then it could become slightly complex and you might have to use APIs rather than native queries.

Singaiah_Chintalapudi
Level 7
January 17, 2019

I am planning to execute it via crx/de. I don't think it makes much difference.

Our hierarchy is very deep probably 10 levels deep.

Lokesh_Shivalingaiah
Level 10
January 21, 2019

I don't want to write a program since that requires a code deployment to get the results. I am planning to execute the query in crx/de.

Here is my SQL2 query:

  

SELECT parent.* FROM [nt:unstructured] AS parent INNER JOIN [nt:base] AS child ON ISDESCENDANTNODE(child, parent)

WHERE ISDESCENDANTNODE(parent, '/content/ABC/en-us') AND (parent.[sling:resourceType] = "abc/components/structure/templateA" AND child.[sling:resourceType]='abc/components/content/componentA')

I would like to include componentB in the query as well so I can get the pages have both component A&B.


I am able to get OR working but for some reason AND is not .. will try and update if I find something