“AEM查询”构建器在搜索中排除文件夹

时间:2017-07-25 02:11:13

标签: search aem query-builder

我需要创建一个查询,其中params就像:

queryParams.put("path", "/content/myFolder");
queryParams.put("1_property", "myProperty");
queryParams.put("1_property.operation", "exists");
queryParams.put("p.limit", "-1");

但是,我需要排除这个毯子文件夹中的某个路径,例如:"/content/myFolder/wrongFolder"并搜索所有其他文件夹(其编号保持不变)

有没有办法这样做?我没有在网上找到它。

我还尝试了unequals操作,因为父路径正在保存在JCR属性中,但仍然没有运气。我实际上需要unlike来避免所有出现的路径。但是没有这样的事情:

path=/main/path/to/search/in
group.1_property=cq:parentPath
group.1_property.operation=unequals
group.1_property.value=/path/to/be/avoided
group.2_property=myProperty
group.2_property.operation=exists
group.p.or=true
p.limit=-1

3 个答案:

答案 0 :(得分:1)

这是一个老问题,但之后您获得更多结果的原因在于您构建查询的方式。编写像这样的查询的正确方法是:

path=/main/path/where
property=myProperty
property.operation=exists
property.value=true
group.p.or=true
group.p.not=true
group.1_path=/main/path/where/first/you/donot/want/to/search
group.2_path=/main/path/where/second/you/donot/want/to/search
p.limit=-1

一些注意事项:您上次评论中的group.p.or将适用于您的所有群组,因为它们未由群组编号描述。如果您希望将OR应用于特定组(但不是所有组),则可以使用:

path=/main/path/where
group.1_property=myProperty
group.1_property.operation=exists
group.1_property.value=true
2_group.p.or=true
2_group.p.not=true
2_group.3_path=/main/path/where/first/you/donot/want/to/search
2_group.4_path=/main/path/where/second/you/donot/want/to/search

此外,数字本身并不重要 - 它们不必是顺序的,只要不重用属性谓词数,这将导致在QB尝试解析它时抛出异常。但是为了可读性和一般惯例,它们通常以这种方式呈现。

我认为你的例子只是为了这个问题而被抛在了一起,但显然你的“不搜索”路径必须是你想要搜索的主路径的子路径,或者在查询中包含它们是多余的,查询不管怎么说都不会搜索它们。

AEM Query Builder Documentation for 6.3

希望这有助于将来。

答案 1 :(得分:0)

使用QueryBuilder可以执行:

map.put("group.p.not",true)
map.put("group.1_path","/first/path/where/you/donot/want/to/search")
map.put("group.2_path","/second/path/where/you/donot/want/to/search")

我还检查了PredicateGroup的类API,它们提供了setNegated方法。我自己从来没有使用它,但我认为你可以否定一个组并将它与你正在搜索的路径结合成一个共同的谓词:

final PredicateGroup doNotSearchGroup = new PredicateGroup();
doNotSearchGroup.setNegated(true);
doNotSearchGroup.add(new Predicate("path").set("path", "/path/where/you/donot/want/to/search"));

final PredicateGroup combinedPredicate = new PredicateGroup();
combinedPredicate.add(new Predicate("path").set("path", "/path/where/you/want/to/search"));
combinedPredicate.add(doNotSearchGroup);

final Query query = queryBuilder.createQuery(combinedPredicate);

答案 2 :(得分:0)

这是在给定的特定组ID上指定运算符的查询。

path=/content/course/
type=cq:Page
p.limit=-1
1_property=jcr:content/event

group.1_group.1_group.daterange.lowerBound=2019-12-26T13:39:19.358Z
group.1_group.1_group.daterange.property=jcr:content/xyz

group.1_group.2_group.daterange.upperBound=2019-12-26T13:39:19.358Z
group.1_group.2_group.daterange.property=jcr:content/abc

group.1_group.3_group.relativedaterange.property=jcr:content/courseStartDate
group.1_group.3_group.relativedaterange.lowerBound=0
group.1_group.2_group.p.not=true
group.1_group.1_group.p.not=true
相关问题