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?