一,Query Search Debugger
http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&query=
二,基本查询
查询/content/geometrixx-gov/en路径下jcr:title为Application Dashboard的所有节点:
path=/content/geometrixx-gov/en
property=jcr:title
property.value=Application Dashboard
p.limit=-1
or(或)查询
path=/content/geometrixx-gov/en
group.1_property=jcr:title
group.1_property.value=Application Dashboard
group.2_property=jcr:title
group.2_property.value=Thank You
group.p.or=true
p.limit=-1
判断存在
path:。。。
group.1_property:jcr:primaryType
group.1_property.value:cq:PageContent
group.2_property:redirectTarget
group.2_property.operation:exists
group.p.or:false
p.limit=-1
判断不存在
path:。。。
group.1_property:jcr:primaryType
group.1_property.value:cq:PageContent
group.2_property:redirectTarget
group.2_property.operation:not
group.p.or:false
p.limit=-1
二,java代码
<%@page import="com.day.cq.search.result.Hit" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.List" %>
<%@page import="java.util.Map" %>
<%@page import="java.util.HashMap" %>
<%@page import="javax.jcr.Session" %>
<%@page import="com.day.cq.search.QueryBuilder" %>
<%@page import="com.day.cq.search.PredicateGroup" %>
<%@page import="com.day.cq.search.Query" %>
<%@page import="org.apache.sling.api.resource.ValueMap" %>
<%@page import="org.apache.sling.api.resource.ModifiableValueMap" %>
<%
String product_path = "/content/geometrixx-media";
Session session = resourceResolver.adaptTo(Session.class);
QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
Map map = new HashMap();
map.put("path", product_path);
map.put("property","jcr:primaryType");
map.put("property.value","cq:Page");
map.put("p.limit","-1");
PredicateGroup predicateGroup = PredicateGroup.create(map);
if (null != queryBuilder) {
Query query = queryBuilder.createQuery(predicateGroup, session);
List<Hit> hitList = query.getResult().getHits();
for(int i=0;i<hitList.size();i++) {
}
}
%>