might be best explain with an example
These are 6 sample nodes
I want to return all nodes where the node name = "shoe1" BUT I do NOT want to return node5. So in my sample nodes, no1 and 3 will be included. Node5 is not included.
How can I do it?
I looked at the nodes and there's nothing in the node properties that can help me. All I have are the names.
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
To return all nodes where the node name is "shoe1" but exclude a specific node, you can use the AEM Query Builder API to construct a query that filters the nodes based on their names and paths.
Here's an example of how you might do this:
// Set up the Query Builder QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class); // Create a query Map<String, String> map = new HashMap<String, String>(); map.put("path", "/content/myhost/products/shoes"); map.put("type", "cq:Page"); map.put("property", "jcr:content/jcr:title"); map.put("property.value", "shoe1"); map.put("p.excludedPaths", "/content/myhost/products/shoes/kids/shoe1"); // Execute the query Query query = queryBuilder.createQuery(PredicateGroup.create(map), resourceResolver.adaptTo(Session.class)); SearchResult result = query.getResult(); // Get the nodes from the search result NodeIterator nodeIterator = result.getNodes(); // Iterate over the nodes and do something with them while (nodeIterator.hasNext()) { Node node = nodeIterator.nextNode(); // Do something with the node }
Thanks,
Monendra
Hi @jayv25585659
To search for nodes using node name, you can use the following inside Querybuilder
path=/content/myhost/products/shoes
nodename=shoe1
Please give it a try.
Lemme know in case I've misunderstood your question.
Best regards,
Himanshu Singhal
It helps, thanks!
Views
Replies
Total Likes
If the path/node filter logic is too complicated then you can write your own predicates and use that in a query
example https://github.com/arunpatidar02/aem63app-repo/blob/master/java/CaseInsensitiveLikePredicate.java
can you please tell me how to use a custom predicate when creating my querybuilder parameter in java? thanks
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/CaseInsensitiveLikePredicate.java
/**
* Custom case insensitive predicate for like operation e.g.
* caseinsensitive.property=jcr:content/@jcr:title
* caseinsensitive.value=queryString %
*
*/
Views
Replies
Total Likes
Here is the cheetsheet which can help when writing the Queries.
It explains on how to get the search results based on node name as well
https://github.com/paulrohrbeck/aem-links/blob/master/querybuilder_cheatsheet.md
Hope this helps
Hi @jayv25585659,
Please refer to https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/develo... to implement custom predicate using java.
To return all nodes where the node name is "shoe1" but exclude a specific node, you can use the AEM Query Builder API to construct a query that filters the nodes based on their names and paths.
Here's an example of how you might do this:
// Set up the Query Builder QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class); // Create a query Map<String, String> map = new HashMap<String, String>(); map.put("path", "/content/myhost/products/shoes"); map.put("type", "cq:Page"); map.put("property", "jcr:content/jcr:title"); map.put("property.value", "shoe1"); map.put("p.excludedPaths", "/content/myhost/products/shoes/kids/shoe1"); // Execute the query Query query = queryBuilder.createQuery(PredicateGroup.create(map), resourceResolver.adaptTo(Session.class)); SearchResult result = query.getResult(); // Get the nodes from the search result NodeIterator nodeIterator = result.getNodes(); // Iterate over the nodes and do something with them while (nodeIterator.hasNext()) { Node node = nodeIterator.nextNode(); // Do something with the node }
Thanks,
Monendra
This is just for the people looking to search a node/page based on node name using the query builder.
you can get it via the below query -:
path=/content/project/us/en/products
type=cq:Page
nodename=product212
or
path=/content/dam/project/us/en
type=nt:file
nodename=product212
You can look for example here on this cheat sheet
https://github.com/paulrohrbeck/aem-links/blob/master/querybuilder_cheatsheet.md
Views
Replies
Total Likes