当前位置: 首页 > 知识库问答 >
问题:

使用AEM查询生成器检索父节点

东郭弘
2023-03-14

我需要使用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个答案

楚洋
2023-03-14

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

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
 类似资料:
  • 我需要得到一些资产节点使用查询生成器我如何搜索我的gving文件夹路径 从这个资产 我只需要得到1,2,3,4,这意味着“myDatas”文件夹包含。需要使用查询生成器获取此节点

  • 我正在构建一个简单的元数据表,从查询中获取数据。我希望能够查询“type”变量的两个选项。然而| |不起作用;当我使用这个时,页面崩溃。

  • 如何在给定节点下列出多个属性的所有属性和各自的值。 例如,在下面的代码中,我只能搜索一个属性。但我需要搜索10个不同的属性(alttext、img、promos等),并获得相应的值(如果存在)。

  • 我有以下工作查询 它在整个路径=/content/dam上运行,所以它遍历所有节点大约20分钟,并给出结果。 当以编程方式使用查询生成器api时,我如何才能批量使用它,比如-遍历1000个节点并按代码执行某些操作,然后继续查询并遍历下1000个节点等等?这可能吗? 谢谢。

  • 查询生成器操作似乎只能处理属性,而不能处理节点名称。 我正在努力实现以下目标, ,其中我不想获取名为的节点。 我怎样才能做到这一点?

  • 我需要创建一个查询,其中参数如下: 但是,我需要排除这个总括文件夹中的某个路径,比如:,然后在所有其他文件夹中搜索(其数量不断变化) 有没有办法做到这一点?我没有在网上找到它。 我还尝试了操作,因为父路径被保存在JCR属性中,但仍然没有运气。我实际上需要来避免路径的所有出现。但是没有这样的事情: