Expand my Community achievements bar.

SOLVED

How to resolve and return correctly content fragments using group

Avatar

Level 3

I am trying to retrieve content fragments from the "ponto-de-parada" model that have the type value "Toll". However, I am not able to get this specific result. It is returning all the fragments based on the "ponto-de-parada" model, including fragments that are not of type "Toll".

What could be wrong and how can I fix it?

Map<String, String> queryParameterMap = new HashMap<>();
queryParameterMap.put("type", NT_DAM_ASSET);
queryParameterMap.put("p.limit", Integer.toString(maxItems));
 
queryParameterMap.put("group.p.or", "true");
queryParameterMap.put("group.1_group.path", "/content/dam/conteúdo-multicanal/rodovias/conteudo/taxas-de-pedagio/riosp");
queryParameterMap.put("group.2_group.path", "/content/dam/conteúdo-multicanal/rodovias/conteudo/ponto-de-parada/riosp");

queryParameterMap.put("group.1_group.property", JcrConstants.JCR_CONTENT + "/data/cq:model");
queryParameterMap.put("group.1_group.property.value", "/conf/myproject/settings/dam/cfm/models/veiculos-com-multiplicadores");
 
queryParameterMap.put("group.2_group.property", JcrConstants.JCR_CONTENT + "/data/cq:model");
queryParameterMap.put("group.2_group.property.value", "/conf/myproject/settings/dam/cfm/models/ponto-de-parada");

//HERE BELOW IT'S THE PROPERTY THAT I WANT TO GET IN CONTENT FRAGMENT
queryParameterMap.put("group.2_group.property_2", JcrConstants.JCR_CONTENT + "/data/master/type");
queryParameterMap.put("group.2_group.property_2.value", "Toll");

PredicateGroup predicateGroup = PredicateGroup.create(queryParameterMap);
Query query = queryBuilder.createQuery(predicateGroup, session);
SearchResult searchResult = query.getResult();
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

A small modification is required for the queryParameterMap: change "property_2" to "2_property."

//HERE BELOW IT'S THE PROPERTY THAT I WANT TO GET IN CONTENT FRAGMENT
queryParameterMap.put("group.2_group.2_property", JcrConstants.JCR_CONTENT + "/data/master/type");
queryParameterMap.put("group.2_group.2_property.value", "Toll");

 You can check an example here: https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/query-builder/quer... 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

A small modification is required for the queryParameterMap: change "property_2" to "2_property."

//HERE BELOW IT'S THE PROPERTY THAT I WANT TO GET IN CONTENT FRAGMENT
queryParameterMap.put("group.2_group.2_property", JcrConstants.JCR_CONTENT + "/data/master/type");
queryParameterMap.put("group.2_group.2_property.value", "Toll");

 You can check an example here: https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/query-builder/quer... 

Avatar

Community Advisor

Hello @NathanVieira 

 

I have also optimized the query a bit. Please check if it suffices your need

 

type=dam:Asset
1_group.1_path=/content/dam/conteúdo-multicanal/rodovias/conteudo/taxas-de-pedagio/riosp
1_group.2_path=/content/dam/conteúdo-multicanal/rodovias/conteudo/ponto-de-parada/riosp
1_group.p.or=true

property=jcr:content/data/cq:model
property.1_value=/conf/myproject/settings/dam/cfm/models/veiculos-com-multiplicadores
property.2_value=/conf/myproject/settings/dam/cfm/models/ponto-de-parada
property=jcr:content/data/master/type
property.value=Toll



Aanchal Sikka

Avatar

Level 3

"This solution didn't work; I need to retrieve content fragments from both models, and only in the 'ponto-de-parada' model, return those that are of type 'Toll'.

I tested it in the QueryBuilder Debugger, and in the way you suggested, it only returns fragments from the 'ponto-de-parada' model because the second property invalidates the first"

type=dam:Asset
1_group.1_path=/content/dam/conteudo-multicanal/rodovias/conteudo/pt/taxas-de-pedagio/riosp
1_group.2_path=/content/dam/conteudo-multicanal/rodovias/conteudo/pt/ponto-de-parada/riosp
1_group.p.or=true


property=jcr:content/data/cq:model
property.value=/conf/App-Rodovias/settings/dam/cfm/models/veiculos-com-multiplicadores
property.2_value=/conf/App-Rodovias/settings/dam/cfm/models/ponto-de-parada
property=jcr:content/data/master/type
property.value=Toll