使用 AEM 查询生成器检索父节点
Retrieve a parent node using 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 作为产品 属性 的值。
从前面的要点开始,我只需要 return 父项,例如:
1) /content/test/us/bar/table
2) /content/test/us/bar/chair
我可以通过编程方式实现我的目标,迭代结果并使用 3 次 getParent() 方法。
我想知道:有没有办法通过查询生成器获取它?
如果您要搜索的 属性 始终存在于已知路径中,则查询可以重写为
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
我需要使用 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 作为产品 属性 的值。
从前面的要点开始,我只需要 return 父项,例如:
1) /content/test/us/bar/table
2) /content/test/us/bar/chair
我可以通过编程方式实现我的目标,迭代结果并使用 3 次 getParent() 方法。
我想知道:有没有办法通过查询生成器获取它?
如果您要搜索的 属性 始终存在于已知路径中,则查询可以重写为
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