Search AEM查询生成器在搜索中排除文件夹

Search AEM查询生成器在搜索中排除文件夹,search,aem,query-builder,Search,Aem,Query Builder,我需要创建一个查询,其中参数如下: queryParams.put("path", "/content/myFolder"); queryParams.put("1_property", "myProperty"); queryParams.put("1_property.operation", "exists"); queryParams.put("p.limit", "-1"); 但是,我需要排除这个总括文件夹中的某个路径,比如:“/content/myFolder/errowfolder

我需要创建一个查询,其中参数如下:

queryParams.put("path", "/content/myFolder");
queryParams.put("1_property", "myProperty");
queryParams.put("1_property.operation", "exists");
queryParams.put("p.limit", "-1");
但是,我需要排除这个总括文件夹中的某个路径,比如:
“/content/myFolder/errowfolder”
,然后在所有其他文件夹中搜索(其数量不断变化)

有没有办法做到这一点?我没有在网上找到它

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

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

使用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,它们提供了一个
setNegatived
方法。我自己从未使用过它,但我认为你可以否定一个组,并将它与你正在搜索的路径组合成一个公共谓词,如:

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);

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

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应用于特定组(但不是所有组),可以使用:

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尝试解析它时引发异常。但为了可读性和一般惯例,它们通常是这样呈现的

我假设您的示例是针对这个问题而创建的,但是很明显,您的“不搜索”路径必须是您要搜索的主路径的子路径,或者将它们包含在查询中是多余的,否则查询将不会搜索它们


希望这对将来的人有所帮助。

以下是在给定的特定组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

如果SQL2查询适用于您,那么您可以执行此查询:从[nt:非结构化]中选择*作为p where(IsDescendatNode(p,[/content/myFolder/]),而不是IsDescendatNode(p,[/content/myFolder/ErrorFolder/]),并包含(p.*‘myProperty’)让我知道这是否有效。@SumantaPakira,我现在不能使用SQL2,因为它需要在应用程序中进行重大更改。因此,目前只在查询生成器中寻找解决方案。group.p.not对我不起作用。我在下面进行了尝试,得到了比之前三次的结果:path=/main/path/where/I/want/to/search group.p.not=true group.1\u path=/first/path/where/you/donot/want/to/search group.2\u property=myProperty group.2\u property.operation=exists group.p.or=true p.limit=-12\u group.p.or=true未对组2进行设置或条件。你能给我正确的语法吗?如果可能的话,你能调查一下吗-