Hi
I am using aem 6.2 version. am trying to query JCR in a service to retrieve information at /content/dam using query builder API but search results are returned as zero. Is there anything wrong in this snippet or any pre-requisite to use querybuilder API.
Map<String,String> map = new HashMap<String,String>();
map.put("path", "/content/dam");
map.put("type", "dam:Asset");
Query damQuery = queryBuilder.createQuery(PredicateGroup.create(map), jcrSession);
SearchResult searchItems = damQuery.getResult();
logger.debug("DAM search query : {}", searchItems.getQueryStatement());
logger.debug("search total match : {}", searchItems.getTotalMatches());
Iterator<Node> nodes = searchItems.getNodes();
while(nodes.hasNext()) {
Node node = nodes.next();
logger.debug("node name : {}",node.getName());
}
This is the query generated in logs query=select [jcr:path], [jcr:score], * from [nt:base] as a where isdescendantnode(a, '/content/dam') /* xpath: /jcr:root/content/dam//* */, path=/content/dam//*); . If i try to execute same query via CRX query builder screen, it works. Same is not working via API call.
Solved! Go to Solution.
Hi
Please try to follow this article:-
Link:- https://helpx.adobe.com/experience-manager/using/htl_querybuilder.html [This is tested article, This article would work for you.]
// Creating a HTML Template Language component that uses the AEM QueryBuilder API
Code Used here is:-
// create query description as hash map
Map<String, String> map = new HashMap<String, String>();
map.put("path", "/content");
map.put("type", "cq:Page");
map.put("group.p.or", "true"); // combine this group with OR
map.put("group.1_fulltext", fulltextSearchTerm);
map.put("group.1_fulltext.relPath", "jcr:content");
map.put("group.2_fulltext", fulltextSearchTerm);
map.put("group.2_fulltext.relPath", "jcr:content/@cq:tags");
// can be done in map or with Query methods
map.put("p.offset", "0"); // same as query.setStart(0) below
map.put("p.limit", "20"); // same as query.setHitsPerPage(20) below
Query query = builder.createQuery(PredicateGroup.create(map), session);
query.setStart(0);
query.setHitsPerPage(20);
SearchResult result = query.getResult();
I hope this would help you.
~kautuk
Are you using the same user/permissions?
Views
Replies
Total Likes
Yes. i have got resourceResolver via ResourceResolverFactory.getResourceResolver(null). Is there any explicit check to be done.
Views
Replies
Total Likes
Hi
Please try to follow this article:-
Link:- https://helpx.adobe.com/experience-manager/using/htl_querybuilder.html [This is tested article, This article would work for you.]
// Creating a HTML Template Language component that uses the AEM QueryBuilder API
Code Used here is:-
// create query description as hash map
Map<String, String> map = new HashMap<String, String>();
map.put("path", "/content");
map.put("type", "cq:Page");
map.put("group.p.or", "true"); // combine this group with OR
map.put("group.1_fulltext", fulltextSearchTerm);
map.put("group.1_fulltext.relPath", "jcr:content");
map.put("group.2_fulltext", fulltextSearchTerm);
map.put("group.2_fulltext.relPath", "jcr:content/@cq:tags");
// can be done in map or with Query methods
map.put("p.offset", "0"); // same as query.setStart(0) below
map.put("p.limit", "20"); // same as query.setHitsPerPage(20) below
Query query = builder.createQuery(PredicateGroup.create(map), session);
query.setStart(0);
query.setHitsPerPage(20);
SearchResult result = query.getResult();
I hope this would help you.
~kautuk
Thanks Kautuk.
I was able to resolve it earlier, issue was i wasn't getting admin resource resolver. Now i've service user to obtain resource resolver and obtaining search results via that. Thanks for your response.
Views
Replies
Total Likes
Views
Likes
Replies