Using Query Builder to query content fragments by variation name? | Community
Skip to main content
Level 4
December 27, 2023
Solved

Using Query Builder to query content fragments by variation name?

  • December 27, 2023
  • 2 replies
  • 2713 views

I'm aware of how to query content fragments based on their variation. I'm trying to figure out how to do this using Query Builder and there isn't much documentation. Only GraphQL documentation. 

 

I've tried to log out the XPath/SQL2 equivalent of a GraphQL query to see how it's done under the hood when performing the GraphQL version of this query in AEM, but I'm finding it difficult to get that query log result. 


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

I am not sure if it serves your purpose but you can try using p.hits = selective which will return variation properties. Change the p.properties value based on your needs.

path = /content/dam/aem-demo type = dam:Asset contentFragment 1_property = jcr:content/data/cq:model 1_property.value = /conf/..../cfm/models/article 2_property = jcr:content/data/web/jcr:primaryType 2_property.operation = exists p.hits = selective p.properties = jcr:path jcr:content/data/web/title jcr:content/data/web/description jcr:content/data/web/tags{ "success": true, "results": 1, "total": 1, "more": false, "offset": 0, "hits": [{ "jcr:path": "/content/dam/aem-demo/..../aem-community", "jcr:content": { "data": { "web": { "description": "<p>Hello World!!<\/p>", "title":"AEM Community", "tags": [ "aem-demo:activity/biking", "aem-demo:activity/running" ] } } } }] }

 

2 replies

Mahedi_Sabuj
Community Advisor
Community Advisor
December 27, 2023

You can use the following query to retrieve article content fragments based on the web variation.

path = /content/dam/aem-demo type = dam:Asset contentFragment 1_property = jcr:content/data/cq:model 1_property.value = /conf/aem-demo/settings/dam/cfm/models/article 2_property = jcr:content/data/web/jcr:primaryType 2_property.operation = exists

Make sure to replace the variation name "web" according to your specific requirements.

Mahedi Sabuj
Preston-3Author
Level 4
December 27, 2023

This is very close. The only problem is I actually need to return the variations themselves. This returns the CF that has the variation, but not the variation itself. 

Mahedi_Sabuj
Community Advisor
Mahedi_SabujCommunity AdvisorAccepted solution
Community Advisor
December 27, 2023

I am not sure if it serves your purpose but you can try using p.hits = selective which will return variation properties. Change the p.properties value based on your needs.

path = /content/dam/aem-demo type = dam:Asset contentFragment 1_property = jcr:content/data/cq:model 1_property.value = /conf/..../cfm/models/article 2_property = jcr:content/data/web/jcr:primaryType 2_property.operation = exists p.hits = selective p.properties = jcr:path jcr:content/data/web/title jcr:content/data/web/description jcr:content/data/web/tags{ "success": true, "results": 1, "total": 1, "more": false, "offset": 0, "hits": [{ "jcr:path": "/content/dam/aem-demo/..../aem-community", "jcr:content": { "data": { "web": { "description": "<p>Hello World!!<\/p>", "title":"AEM Community", "tags": [ "aem-demo:activity/biking", "aem-demo:activity/running" ] } } } }] }

 

Mahedi Sabuj
kautuk_sahni
Community Manager
Community Manager
January 3, 2024

@preston-3 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni
Preston-3Author
Level 4
January 3, 2024

I marked the answer that comes closest, but there doesn't appear to be a Query Builder equivalent to the same query that you can perform in GraphQL.