While working with the JCR SQL2 Queries, you may encounter scenarios where content is distributed across various branches of the repository. Querying these branches efficiently is key to implement features to capture requirements. In this article, we will focus o how to collect and query for distributed across various branches of the repository. Using the ISDESCENDANTNODE feature of the JCR SQL Query proves it possible.
Understanding ISDESCENDANTNODE
ISDESCENDANTNODE is a condition in JCR SQL2 that checks if a node is a descendant of another, based on their paths. It is particularly beneficial for querying content hierarchies. Imagine you have content in different branches (content tree) of your AEM repository. You want to search across these branches simultaneously, without running separate queries. This is where ISDESCENDANTNODE shines.
By specifying multiple paths within the ISDESCENDANTNODE condition, you can search for content across these paths concurrently, streamlining your queries. This powerful feature simplifies and optimizes the content retrieval process in AEM.
Finding all cq:Pages under 1 path
with the jcr:content/jcr:title CONTAINS %terms%
1 2 3 | SELECT * FROM [cq:Page] WHERE ISDESCENDANTNODE('/content/sourcedcode/us/') AND CONTAINS([jcr:content/jcr:title], 'terms') |
Finding all cq:Pages under 2 paths
with the jcr:content/jcr:title CONTAINS %terms%
1 2 3 4 | SELECT * FROM [cq:Page] WHERE (ISDESCENDANTNODE('/content/sourcedcode/us/') OR ISDESCENDANTNODE('/content/sourcedcode/ca/') AND CONTAINS([jcr:content/jcr:title], 'terms') |
Finding all cq:Pages under 3 paths
with the jcr:content/jcr:title CONTAINS %terms%
1 2 3 4 5 | SELECT * FROM [cq:Page] WHERE (ISDESCENDANTNODE('/content/sourcedcode/us/') OR ISDESCENDANTNODE('/content/sourcedcode/ca/') OR ISDESCENDANTNODE('/content/sourcedcode/pl/')) AND CONTAINS([jcr:content/jcr:title], 'terms') |

