Is it possible to use multiple PredicateGroups within QueryBuilder?
e.g.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi Darren,
I believe your requirement should be solved by using multiple predicate groups like below..
PredicateGroup predicateGroup1 = null; Map<String, String> map = new HashMap<String, String>(); PredicateGroup predicateGroup2 = null; Map<String, String> map2 = new HashMap<String, String>(); map1.put("path", "/content"); map1.put("type", "cq:Page"); map1.put("group.p.or", "true"); map1.put("group.1_fulltext", fulltextSearchTerm); map1.put("group.1_fulltext.relPath", "jcr:content"); map1.put("group.2_fulltext", fulltextSearchTerm); map1.put("group.2_fulltext.relPath", "jcr:content/@cq:tags"); map2.put("group.p.or", "true"); map2.put( "group.3_path" , "/content/geometrixx/en/company/management" ); map2.put( "group.4_path" , "/content/geometrixx/en/company/bod" ); ... predicateGroup1 = PredicateGroup.create(map); predicateGroup2 = PredicateGroup.create(map2); predicateGroup1.add(predicateGroup2); ... queryBuilder.createQuery(predicateGroup1, session);
Hope it helps.
Regards
Vatsal
Views
Replies
Total Likes
Hi Darren,
I believe your requirement should be solved by using multiple predicate groups like below..
PredicateGroup predicateGroup1 = null; Map<String, String> map = new HashMap<String, String>(); PredicateGroup predicateGroup2 = null; Map<String, String> map2 = new HashMap<String, String>(); map1.put("path", "/content"); map1.put("type", "cq:Page"); map1.put("group.p.or", "true"); map1.put("group.1_fulltext", fulltextSearchTerm); map1.put("group.1_fulltext.relPath", "jcr:content"); map1.put("group.2_fulltext", fulltextSearchTerm); map1.put("group.2_fulltext.relPath", "jcr:content/@cq:tags"); map2.put("group.p.or", "true"); map2.put( "group.3_path" , "/content/geometrixx/en/company/management" ); map2.put( "group.4_path" , "/content/geometrixx/en/company/bod" ); ... predicateGroup1 = PredicateGroup.create(map); predicateGroup2 = PredicateGroup.create(map2); predicateGroup1.add(predicateGroup2); ... queryBuilder.createQuery(predicateGroup1, session);
Hope it helps.
Regards
Vatsal
Views
Replies
Total Likes
VatsalGupta wrote...
Hi Darren,
I believe your requirement should be solved by using multiple predicate groups like below..
PredicateGroup predicateGroup1 = null;
Map<String, String> map = new HashMap<String, String>();
PredicateGroup predicateGroup2 = null;
Map<String, String> map2 = new HashMap<String, String>();
map1.put("path", "/content");
map1.put("type", "cq:Page");
map1.put("group.p.or", "true");
map1.put("group.1_fulltext", fulltextSearchTerm);
map1.put("group.1_fulltext.relPath", "jcr:content");
map1.put("group.2_fulltext", fulltextSearchTerm);
map1.put("group.2_fulltext.relPath", "jcr:content/@cq:tags");
map2.put("group.p.or", "true");
map2.put( "group.3_path" , "/content/geometrixx/en/company/management" );
map2.put( "group.4_path" , "/content/geometrixx/en/company/bod" );
...
predicateGroup1 = PredicateGroup.create(map);
predicateGroup2 = PredicateGroup.create(map2);
predicateGroup1.add(predicateGroup2);
...
queryBuilder.createQuery(predicateGroup1, session);
Hope it helps.
Regards
Vatsal
Thanks Vatsal. I would not have thought you could nest PredicateGroups.
Views
Replies
Total Likes
Your welcome.
In fact if you would want to do a bit more complex query e.g applying a NOT operation on a Predicate group, that can also be done -
predicateGroup1 = PredicateGroup.create(map); predicateGroup2 = PredicateGroup.create(map2); predicateGroup2.setNegated(true); predicateGroup1.add(predicateGroup2);
You can check more operations here -
http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/search/PredicateGroup.html
Regards
Vatsal
Views
Replies
Total Likes
Is there any way, we can implement partial text search instead of fulltextsearch?
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies