Expand my Community achievements bar.

QueryBuilder API combining multiple types for a query

Avatar

Level 2

Hello,

I am attempting to use the querybuilder API to search for two different 'types' in querybuilder. I have tried putting each type into a group like below - it isn't working

map.put("path", paths); map.put("group.p.and", "true"); map.put("group.1_type", "nt:unstructured"); map.put("group.2_type", "cq:Page"); map.put("group.1_fulltext", Keyword); map.put("group.1_fulltext.relPath", "jcr:content"); map.put("group.2_relativedaterange.property","nameofcomponentproperty"); map.put("group.2_relativedaterange.lowerBound","-1d"); // -1d is anything equal to or greater than todays date map.put("group.2_relativedaterange.upperBound",""); map.put("orderby", "@offerdatetime"); // 

Basically, what I am attempting to do is search for the nt:unstructured node where my desired results are inside of a component which can be used more than once on a page, each listing of the component is posting a different date result which I am using the daterange properties to query through the results. In the code example above I have removed the daterange variables to explain my problem better. The daterange is interchangeable. I have also been tasked with using a fulltext search to query through the jcr:content of the text where each one of the pages where the previously mentioned multi-used component is located. This search will take the keyword and return each event where the fulltext query is matched. I am having trouble combining the queries to work together. I have gotten each instance to work separately but have problems when attempting to use the type cq:Page and nt:unstructured. Thanks in advance for any help.

2 Replies

Avatar

Administrator

Hi 

I guess, Join of two group work for you:-

Please have a look at the link[1] shared by Scott:-

[1] http://aemcq5.blogspot.in/2014/11/cq5-querybuilder-simplified.html

//

Lets make of join of two groups in this example. This is a tricky one and need understanding regarding the predicates and filters in CQ5 querybuilder.

When we try to create two group, we can assign separate paths and type at the group level. This is known as filtering predicate. All the xpath predicates need be same in this case otherwise if we apply the group level ORing separately using p.or = true, the execution time of such a query will be prohibitively long.

Let's look at below query:

1_group.1_group.path=/content/geometrixx/en
1_group.2_group.path=/content/dam/geometrixx
1_group.p.or=true
2_group.1_group.type = cq:Page
2_group.2_group.type = dam:Asset
2_group.p.or=true
3_group.2_group.fulltext = marketing:interest/product
3_group.2_group.fulltext.property = @jcr:content/cq:tags
3_group.1_group.1_group.fulltext = marketing:interest/product
3_group.1_group.1_group.fulltext.property = @jcr:content/metadata/cq:tags
3_group.1_group.2_group.fulltext = marketing:interest/services
3_group.1_group.2_group.fulltext.property = @jcr:content/metadata/cq:tags
3_group.1_group.p.and=true
3_group.p.or=true

This will find all the nodes with either type cq:Page or dam:Asset and tagged with cq:tags at the same hierarchy from jcr:content.Also note that we are applying 2 tags match for the asset tags. It is important to remember that group level ORing for path and type along with same set of properties will work relatively fast.

We can screw up the execution of above query if we do ORing for say group1 by doing following:
group.1_group.p.or=true.
This will result in a very inefficient and long executing query. Beware of such cases and implement the same logic in business layer by using separate queries and combining result rather than using the same one.

 

I hope this will help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 2
1_group.1_group.path=/path 1_group.2_group.path=/path 1_group.p.or=true 2_group.1_group.type = cq:Page 2_group.2_group.type = nt:unstructured 2_group.p.or=true 3_group.2_group.1_group.fulltext = Term 3_group.2_group.1_group.fulltext.property = jcr:content 3_group.2_group.2_group.daterange.property = nameofproperty 3_group.2_group.2_group.daterange.lowerBound = 2016-06-22 3_group.2_group.2_group.daterange.upperBound = 2016-08-11 3_group.p.and=true

This is the code that I have used from the previously posted link. The problem here is that the fulltext.property search where 'Term' is listed is only querying through the node listed under nt:unstructured instead of the cq:Page. What am I doing wrong?