Query to fetch the nodes under /content
Can someone please let me know on how to fetch the nodes that are present under /content ? I need to know the query.
Can someone please let me know on how to fetch the nodes that are present under /content ? I need to know the query.
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,
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.