2

I need to have a JCR SQL query of this form :

select * from jcr:content where cq:template like '%myTemplate%' and ( jcr:path like '%path1%' or jcr:path like '%path2%')

But I get an exception saying that "incorrect use of property jcr:path" Is there a quick workaround for this ? The number of paths to search in may vary each time based on user selection.

Riju Mahna
  • 6,718
  • 12
  • 52
  • 91

2 Answers2

2

I tried the following query in CQ's Query tool and it worked.

SELECT * FROM [cq:PageContent] WHERE [cq:PageContent].[cq:template] LIKE '%content%' AND ( isdescendantnode('/content/geometrixx/fr/') OR isdescendantnode('/content/geometrixx/en/'))

But ISDESCENDANTNODE requires an absolute path and i think relative ones wouldnt work.

rakhi4110
  • 9,253
  • 2
  • 30
  • 49
  • 1
    SQl2 does work on different paths at the same time. The above example by @Rakhi seems to work. You have to keep in mind that all the different paths should be put in one bracket if all the isdescendant path conditions are not combined in brackets, the query starts giving out bad results. Like ( isdec(path1) or/and isdec(path2)) and not like isdesc(path1) or/and idesc(path2) – Sam Thadhani Mar 18 '14 at 22:35
1

As you've noticed, it's impossible to use multiple path comparisons in the JCR queries. You have a few options here:

  1. Create a few queries, one per path.
  2. Add some custom attribute to jcr:content node marking the pages you are interested in and use it instead of paths.
  3. Iterate over path1 and path2 subtrees rather than query them.
Tomek Rękawek
  • 9,204
  • 2
  • 27
  • 43
  • Yeah.. I noticed... its not allowed to query over multiple paths. So I just queried using the parent of them all and then iterated the list of results to filter out the desired results. Thanks – Riju Mahna Nov 21 '13 at 21:58