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

如何向QueryBuilder查询添加“where not”

呼延沈义
2023-03-14

我想搜索整个内容树,但不搜索在其底部具有“请勿搜索”属性的特定树。

查询生成器API页面不引用除AND和OR之外的任何内容。

是否可以从搜索中排除路径,或者我只能显式地包括路径?

前三行是“/content和/content/path/es”。我想要“/content而不是(/content/path/es)”

map.put("group.1_path", "/content");
map.put("group.2_path", "/content/path/es");
map.put("group.p.or","false");

我试了下两个真假都没有效果。

map.put("group.2_path.p.not", "true");
map.put("group.2_path.not", "true");
map.put("group.2_path", "not('/content/path/es')");

我找不到任何提到“不是”或“不是”的其他名称的文档可能会被用来代替。

共有3个答案

齐浩淼
2023-03-14

这是一个非常简单的实现。使用

map.put("group.p.not",true)
map.put("group.1_path","/path1/where/you/donot/want/to/search")
map.put("group.2_path","/path2/where/you/donot/want/to/search")
雷逸仙
2023-03-14

我不确定您使用的是什么版本的CQ(您链接到5.4文档),但是在5.5及以上版本中,PredicateGroup类有一个setnegated方法来排除与定义的组相匹配的结果。

您不能对单个谓词设置否定,但没有什么可以阻止您创建一个只包含您希望否定的谓词的组:

Predicate pathPredicate = new Predicate("path").set("path", "/content/path/es");
PredicateGroup doNotSearchGroup = new PredicateGroup();

doNotSearchGroup.setNegated(true);
doNotSearchGroup.add(pathPredicate);

Query query = queryBuilder.createQuery(doNotSearchGroup);

编辑:为了更新您的注释,您应该能够将PredicateGroup添加到另一个PredicateGroup(因为PredicateGroupPredicate的子类)。因此,一旦您有了否定的组,将其与路径搜索结合起来:

Predicate pathPredicate = new Predicate("path");
pathPredicate.set("path", "/content");

PredicateGroup combinedPredicate = new PredicateGroup();
combinedPredicate.add(pathPredicate);
combinedPredicate.add(doNotSearchGroup);

Query query - queryBuilder.createQuery(combinedPredicate);
谭健柏
2023-03-14

是的,这是可能的。但这并不完全是你所尝试的方式。

可以使用属性谓词求值器排除具有某些属性的页。

例如,如果要排除jcr:content节点中具有属性“donotsearch”的页面,则可以使用现有的属性操作进行查询

map.put("path", "/content/geometrixx/en/toolbar");
map.put("type", "cq:Page");
/* Relative path to the property to check for */
map.put("property", "jcr:content/donotsearch"); 
/* Operation to perform on the value of the prop, in this case existence check */
map.put("property.operation", "exists"); 
/* Value for the prop, false = not, by default it is true */
map.put("property.value", "false"); 

这将导致下面的XPath查询

/jcr:root/content/geometrixx/en/toolbar//element(*, cq:Page)
[
not(jcr:content/@donotsearch) 
]

但是,如果您想为属性donotsearch排除具有特定值的页面,那么您可以更改上述查询,如下所示

map.put("property", "jcr:content/donotsearch"); //the property to check for
map.put("property.operation", "equals"); // or unequals or like etc..
map.put("property.value", "/*the value of the property*/");

通过参考文档,您可以找到许多其他有关查询的信息。

 类似资料:
  • 我使用的是Spring Data JPA 1.7.1 这里有一个例子:

  • 我正在使用React,使用NodeJS将数据发送到我的PostgreSQL数据库。我的songs表中有一个外键,它引用了albums表中的id。我的问题是,如何将我第一次插入的id返回到第二次插入的相册中?以下是我目前的代码: 我还没有将专辑id添加到我的歌曲插入中。我在等着看如何把唱片id的值输入到我的第二个插页中?

  • 问题内容: 我想通过使用Postgresql的“ NULLS LAST”选项对模型进行排序。怎么做? 我尝试了类似的东西 但是我明白了 “无法将关键字’NULLS LAST’解析为字段” 问题答案: 此功能已添加到Django 1.11中。 https://docs.djangoproject.com/en/dev/releases/1.11/

  • 我有如下要求。 从UI获取place子句作为字符串,任何选项都可以在Spring Boot中的place子句中添加字符串以查询mongo DB 例如:(eventType以“asdf”和age开头 在sql中,我们可以添加where子句,但不确定如何在mongoDB的springboot中做到这一点 注意:字符串是动态的,没有特定的模式。括号可以嵌套。Spring防尘套前端角度和维修 提前感谢

  • 我对meta_query有些情境问题。客户搜索四,但结果包括私人(原始词是私人的)。我想只显示IV(罗马数字)包括后。我的meta_query搜索从标题,子标题和自定义插件的描述。我找到了REGEXP,但我找不到从标题、子标题和描述中找到漫游数字的正确方法。 客户只能找到罗马数字,也可以找到任何单词等。

  • 本文向大家介绍如何在MySQL查询中向datetime字段添加日期?,包括了如何在MySQL查询中向datetime字段添加日期?的使用技巧和注意事项,需要的朋友参考一下 要将日期添加到日期时间字段,请使用DATE_ADD()函数。语法如下- 让我们首先创建一个表- 借助插入当前日期,然后使用date_add()函数添加一天。 要在表格中插入一天,以下是查询- 在select语句的帮助下显示记录。