How to resolve and return correctly content fragments using group | Community
Skip to main content
Level 3
September 13, 2023
Solved

How to resolve and return correctly content fragments using group

  • September 13, 2023
  • 2 replies
  • 1043 views

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();
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 Mahedi_Sabuj

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/querybuilder-api.html?lang=en#search-for-multiple-properties 

2 replies

Mahedi_Sabuj
Community Advisor
Mahedi_SabujCommunity AdvisorAccepted solution
Community Advisor
September 14, 2023

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/querybuilder-api.html?lang=en#search-for-multiple-properties 

Mahedi Sabuj
aanchal-sikka
Community Advisor
Community Advisor
September 14, 2023

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
Level 3
September 26, 2023

"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