multiple groups predicategroup query | Community
Skip to main content
sreenu539
Level 7
September 23, 2022
Solved

multiple groups predicategroup query

  • September 23, 2022
  • 1 reply
  • 744 views

Hi All,

 

I have below query to be executed in AEM Java.

Author authors a multifield component( consists fragment path , fragment tags) to pull multiple content fragments based on path , tags. 

Here I have path1 with some tags, path2 with some different tags.

result: select (path1 matching any of authored tags for path1) OR ( path2, matching any authored tags for path2)

 

 

group ( (group1 (path1 , match any authored tags authored for path1)) OR (group2 (path2, match any authored tags authored for path2)) )

 

 

 

 

type=dam:AssetContent group.p.or=true group.1_group.path=/content/dam/site1/qa group.1_group.1_property.or=true group.1_group.1_property=data/master/cq:tags group.1_group.1_property.1_value=we-retail:activity group.1_group.1_property.2_value=we-retail:gender group.2_group.path=/content/dam/site1/qa2 group.2_group.1_property.or=true group.2_group.1_property=data/master/cq:tags group.2_group.1_property.1_value=facebook: group.2_group.1_property.2_value=experience-fragments:

 

 

 

  

Question: what is the best way to construct above query in AEM Java.

Do I need to iterate through an index and have index appended group text , property text and construct Map and provide it to PredicateGroup class? 

 

Thanks,

Sri

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

Below is the sample code to run the query using AEM querybuilder APIs. 

 

Map<String, String> map = Maps.newHashMap();
        
        map.put("type", "dam:AssetContent");
        map.put("group.p.or", "true")
        ...
        ....
        //Put other items in the map using index by looping through multifield items


        Session session = resourceResolver.adaptTo(Session.class);
        Query query = queryBuilder.createQuery(PredicateGroup.create(map), session);

        SearchResult result = query.getResult();
        Iterator<Resource> resultIterator = result.getResources();
        while (resultIterator.hasNext()){
            //Adapt the resource to a sling model and do the operations
        }
        

Hope that helps!

1 reply

Saravanan_Dharmaraj
Community Advisor
Saravanan_DharmarajCommunity AdvisorAccepted solution
Community Advisor
September 25, 2022

Below is the sample code to run the query using AEM querybuilder APIs. 

 

Map<String, String> map = Maps.newHashMap();
        
        map.put("type", "dam:AssetContent");
        map.put("group.p.or", "true")
        ...
        ....
        //Put other items in the map using index by looping through multifield items


        Session session = resourceResolver.adaptTo(Session.class);
        Query query = queryBuilder.createQuery(PredicateGroup.create(map), session);

        SearchResult result = query.getResult();
        Iterator<Resource> resultIterator = result.getResources();
        while (resultIterator.hasNext()){
            //Adapt the resource to a sling model and do the operations
        }
        

Hope that helps!