使用AEM查询构建器检索父节点

时间:2019-07-01 10:06:01

标签: aem query-builder

我需要使用AEM查询构建器来检索父节点。

例如,这是我的查询:

path:/content/test/us/bar
1_property:product
1_property.operation:exists

2_property:product
2_property.value:8003170008212

此查询允许我检索以下元素:

1) /content/test/us/bar/table/jcr:content/releated/product/2  
2) /content/test/us/bar/chair/jcr:content/releated/product/1

使用此查询,可以检索/ content / test / us / bar下放置的所有元素,其中包含8003170008212作为产品属性的值。

从前面的要点开始,我只需要返回父项,所以例如:

1) /content/test/us/bar/table
2) /content/test/us/bar/chair

我可以通过编程实现目标,迭代结果并使用3倍的getParent()方法。

我想知道:有没有办法通过查询生成器来获取它?

1 个答案:

答案 0 :(得分:3)

如果您要搜索的属性始终存在于已知路径中,则查询可以重写为

path=/content/test/us/bar
1_property=jcr:content/related/product
1_property.operation=exists

2_property=jcr:content/related/product
2_property.value=8003170008212 

这将导致

/content/test/us/bar/table
/content/test/us/bar/chair

避免循环遍历结果并查找父节点。

例如,在我的本地环境中进行以下查询

path=/content/we-retail/language-masters/en
1_property=displayMode
1_property.operation=exists

2_property=displayMode
2_property.value=singleText

产生

/content/we-retail/language-masters/en/experience/wester-australia-by-camper-van/jcr:content/root/responsivegrid/contentfragment
/content/we-retail/language-masters/en/experience/arctic-surfing-in-lofoten/jcr:content/root/responsivegrid/contentfragment
/content/we-retail/language-masters/en/experience/steelhead-and-spines-in-alaska/jcr:content/root/responsivegrid/contentfragment
/content/we-retail/language-masters/en/experience/hours-of-wilderness/jcr:content/root/responsivegrid/contentfragment
/content/we-retail/language-masters/en/experience/skitouring/jcr:content/root/responsivegrid/contentfragment
/content/we-retail/language-masters/en/experience/fly-fishing-the-amazon/jcr:content/root/responsivegrid/contentfragment

但是将以下查询重写为

path=/content/we-retail/language-masters/en
1_property=jcr:content/root/responsivegrid/contentfragment/displayMode
1_property.operation=exists

2_property=jcr:content/root/responsivegrid/contentfragment/displayMode
2_property.value=singleText

产生

/content/we-retail/language-masters/en/experience/wester-australia-by-camper-van
/content/we-retail/language-masters/en/experience/arctic-surfing-in-lofoten
/content/we-retail/language-masters/en/experience/steelhead-and-spines-in-alaska
/content/we-retail/language-masters/en/experience/hours-of-wilderness
/content/we-retail/language-masters/en/experience/skitouring
/content/we-retail/language-masters/en/experience/fly-fishing-the-amazon