Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

multiple groups predicategroup query

Avatar

Level 6

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

1 Accepted Solution

Avatar

Correct answer by
Level 8

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!

View solution in original post

1 Reply

Avatar

Correct answer by
Level 8

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!