Reputation: 778
I am building a simple meta-data table that gets the data from a query. I want to be able to query on two options for the 'type' variable. the || is not working however; when I use this the page crashes.
Map<String, String> predicates = new HashMap<String, String>();
predicates.put("path", searchPath);
predicates.put("type", "cq:Page||dam:Asset");
predicates.put("orderby", orderBy);
QueryBuilder qb = resourceResolver.adaptTo(QueryBuilder.class);
Session session = resourceResolver.adaptTo(Session.class);
Query query = qb.createQuery(PredicateGroup.create(predicates), session);
query.setHitsPerPage(0);
Upvotes: 0
Views: 3178
Reputation: 3402
You have to use groups to query with OR condition. The code for your search should be
predicates.put("path", searchPath);
predicates.put("group.p.or", "true");
predicates.put("group.1_type", "cq:Page");
predicates.put("group.2_type", "dam:Asset");
predicates.put("orderby", orderBy);
You can use the query builder debugger to play around with the query builder, http://localhost:4502/libs/cq/search/content/querydebug.html?charset=UTF-8&query=path%3D%2Fcontent%0D%0Agroup.p.or%3Dtrue%0D%0Agroup.1_type%3Dcq%3APage%0D%0Agroup.2_type%3Ddam%3AAsset%0D%0A%0D%0A
Upvotes: 2