Expand my Community achievements bar.

SOLVED

Query to fetch the nodes under /content

Avatar

Level 4

Can someone please let me know on how to fetch the nodes that are present under /content ? I need to know the query.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

The following is the AEM query in java to fetch all the nodes under /content path.

Sample code:

Map predicateMap = new HashMap();

//path predicate is used to search under a particular hierarchy ("/content" here)

map.put("path", "/content");

//type predicate is used for searching particular nodetype only

//map.put("type", "cq:Page");  (It will search only cq:Page nodes under /content)

//map.put("type", "nt:file");  (It will search only nt:file nodes under /content)

//map.put("type", "sling:Folder");  (It will search only cq:Page nodes under /content)

//nodename predicate is used to search exact nodenames for the result set

//map.put("nodename","HomePage"); (It will search for HomePage node under /content)

Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);

  

//Get search results

SearchResult result = query.getResult();

//Iterate query results

for (Hit hit : result.getHits()) {  

// Write your logic here  

NOTE: Please customize the above query to fetch the nodes under /content as per your requirement.

By default, the query builder json servlet displays a maximum of 10 hits. Adding the following parameter allows the servlet to display all query results:

map.put("p.limit", "-1");

Please refer the links below for more details:

http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/

https://hashimkhan.in/2015/12/02/query-builder/

http://aemcq5.blogspot.in/2014/11/cq5-querybuilder-simplified.html

We hope this helps!

Regards,

TechAspect Solutions

View solution in original post

3 Replies

Avatar

Level 3

Hi,

Use query debugger to get the nodes under /content give the property of node you want to search and the path you want to search.

"http://hostname:port/libs/cq/search/content/querydebug.html"

Below URL provides you details required.

http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/

Thanks

Avatar

Level 6

You can go for sql2 query also. following links might help. they have many sample query. generate yours as needed.

http://drfits.com/jcr-sql2-query-with-examples/

JCR Query Cheat Sheet - Community Wiki - Magnolia

Avatar

Correct answer by
Level 7

Hi,

The following is the AEM query in java to fetch all the nodes under /content path.

Sample code:

Map predicateMap = new HashMap();

//path predicate is used to search under a particular hierarchy ("/content" here)

map.put("path", "/content");

//type predicate is used for searching particular nodetype only

//map.put("type", "cq:Page");  (It will search only cq:Page nodes under /content)

//map.put("type", "nt:file");  (It will search only nt:file nodes under /content)

//map.put("type", "sling:Folder");  (It will search only cq:Page nodes under /content)

//nodename predicate is used to search exact nodenames for the result set

//map.put("nodename","HomePage"); (It will search for HomePage node under /content)

Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);

  

//Get search results

SearchResult result = query.getResult();

//Iterate query results

for (Hit hit : result.getHits()) {  

// Write your logic here  

NOTE: Please customize the above query to fetch the nodes under /content as per your requirement.

By default, the query builder json servlet displays a maximum of 10 hits. Adding the following parameter allows the servlet to display all query results:

map.put("p.limit", "-1");

Please refer the links below for more details:

http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/

https://hashimkhan.in/2015/12/02/query-builder/

http://aemcq5.blogspot.in/2014/11/cq5-querybuilder-simplified.html

We hope this helps!

Regards,

TechAspect Solutions