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.
Solved! Go to Solution.
Views
Replies
Total Likes
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"
]
}
}
}
}]
}
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.
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.
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"
]
}
}
}
}]
}
This works. The problem for us is that it returns the results in a JSON structure where the names of the nodes are different. So we still have to adjust to that. I would be curious if there's a way to do this query (even in SQL2) where the results are as if the variation replaced the "master" values. GraphQL can do this. It looks like this.
{
myModelList(
variation: "myvariation1"
filter: {_variations: {_expressions: [{value: "myvariation1", _operator: EQUALS}]}}
) {
items {
_path
somefield {
plaintext
}
}
}
}
The value returns without the variation node, so it's easy to convert it without needing to dynamically rename JSON nodes (which is a problem with a library like Jackson, for example.
{
"data": {
"myModelList": {
"items": [
{
"_path": "/content/dam/mypath",
"somefield": {
"plaintext": "Some plain text for this variation myvariation1"
}
}
]
}
}
}
@Preston 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.
Views
Replies
Total Likes
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.
Views
Likes
Replies