Querybuilder search for only single tag | Community
Skip to main content
cqsapientu69896
Level 4
September 30, 2016

Querybuilder search for only single tag

  • September 30, 2016
  • 2 replies
  • 1823 views

I am using Querybuilder to search for pages that are tagged with specific tags. The issue is Querybuilder is creating an xpath query that searches for all child tags of the tag along-with the main tag. I want it to search for only the parent tag and not the child tags. Using PredicateGroup to combine all tags--

map.put("path", searchPath); map.put("type", "cq:Page"); map.put("orderby", "@jcr:content/cq:lastModified"); PredicateGroup tagsPredicateGroup = new PredicateGroup(); PredicateGroup searchGroup = PredicateGroup.create(map); PredicateGroup tagsPredicateGroup = new PredicateGroup(); tagsPredicateGroup.setAllRequired(false); if (tagsArray != null && tagsArray.length > 0) { for (Tag tag : tagsArray) { tagsPredicateGroup.add(createSingleTagPredicate(tag)); } } searchGroup.add(tagsPredicateGroup); Query query = queryBuilder.createQuery(searchGroup, session); query.setHitsPerPage(10); query.setStart(0); private PredicateGroup createSingleTagPredicate(Tag tag) { Map<String, String> tagMap = new HashMap<String, String>(); tagMap.put("tagid.property", "jcr:content/cq:tags"); tagMap.put("tagid", tag.getTagID()); return PredicateGroup.create(tagMap); }

If a component is configured to search for geometrixx-outdoors:apparel and geometrixx-media:events tags; then it also returns those pages which are tagged with geometrixx-outdoors:apparel/coats and geometrixx-media:events/festivals as well. How can I make it search for only the parent tag and not the child tag using querybuilder?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Feike_Visser1
Adobe Employee
Adobe Employee
September 30, 2016

To me you can do a search that is property/value based, then you are not using tag-search functionality.

smacdonald2008
Level 10
September 30, 2016

See this AEM community article - it talks about how to perform custom search predicates: 

https://helpx.adobe.com/experience-manager/using/customtags1.html

This will most certainly point you in the right direction...