Expand my Community achievements bar.

SOLVED

Query JCR to fetch pages based on some conditions

Avatar

Level 9


Hi All,

path=/content/www/xx/xx
type=nt:unstructured
1_property=abcd
1_property.operation=exists
2_property=efgh
2_property.operation=exists
3_property=ijkl
3_property.operation=exists
p.limit=-1

We want to retrieve pages, only when a specific component included in a page [there are multiple components having similar properties] has these properties(abcd,efgh & ijkl).

The above query when run in http://localhost:4502/libs/cq/search/content/querydebug.html is not working as per our requirement.

Can someone please tweak this query to meet our requirements.

Any thoughts will be really helpful.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Read this article - there are different ways in which to query JCR. Also - use the AEM Query tool to experiment with different query searches: /crx/explorer/ui/search.jsp.

http://cq-ops.tumblr.com/post/23544023402/how-to-query-cqs-jcr-with-sql-or-xpath

I found this tool to be very useful

View solution in original post

7 Replies

Avatar

Level 2

Is there anything unique for this component?

if yes then use that property in your search query or you can use sling:resourceType property with the default value of your component i.e. /apps/abc/components/xyz. then it will return the result with all nodes having this property. ex - 

/content/geometrixx-outdoors/en/activities/nairobi-runners-running/jcr:content/par/product_reference... 

Iterate this result set &  split each URL on the basic of /jcr:content then first part will be the page URL.

Avatar

Level 2

type=nt:unstructured
path=/content/xyz
1_property=cq:commerceType
1_property.operation=exists
2_property=productData
2_property.operation=exists
3_property=cq:isCancelledForChildren
3_property.operation=exists

 

I am using this query for finding all nt:unstructured node having properties "cq:commerceType, productData, cq:isCancelledForChildren". this query is working fine and returns expected result. If you are not able to find it working then do the debugging by using one by one condition & check results.

Avatar

Level 9


Hi Ankur,

Thank you for your reply.

I added sling:resourceType property and the modified query as below, But still it doesnt seem to be working.

path=/content/xxx/xx/xx
type=nt:unstructured
1_property=sling:resourceType
1_property.value=x/x/x/x/x
2_property=abcd
2_property.operation=exists
3_property=efgh
3_property.operation=exists
4_property=ijkl
4_property.operation=exists
p.limit=-1

Your thoughts on this will be really helpful.

Avatar

Level 9


Hi Ankur,

Thank you for your reply.

The query is working fine for me. But the problem is I want to find only pages which has a specific component which has these properties.
There are many components with same properties and I do not want those to come up in results.

Avatar

Correct answer by
Level 10

Read this article - there are different ways in which to query JCR. Also - use the AEM Query tool to experiment with different query searches: /crx/explorer/ui/search.jsp.

http://cq-ops.tumblr.com/post/23544023402/how-to-query-cqs-jcr-with-sql-or-xpath

I found this tool to be very useful

Avatar

Employee

Hi

Could you elaborate what sort of result you get? Too much? Not at all?
How much time does it take to the query to render the results?

Avatar

Level 9

Hi Carlino,

Nope, It did not throw up any results.