Professional Documents
Culture Documents
Query Builder AEM Document
Query Builder AEM Document
Adobe (www.adobe.comhttp://www.adobe.com/go/gnav_adobe_logo_en_us)
Products (www.adobe.comhttp://www.adobe.com/go/gnav_products_en_us) Solutions (www.adobe.comhttp://www.adobe.com/go/gnav_solutions_en_us) Learning
(www.adobe.comhttp://www.adobe.com/go/gnav_learning_en_us) Help (www.adobe.comhttp://www.adobe.com/go/gnav_help_en_us) Downloads
(www.adobe.comhttp://www.adobe.com/go/gnav_downloads_en_us) Company (www.adobe.comhttp://www.adobe.com/go/gnav_company_en_us)
Store (www.adobe.comhttp://www.adobe.com/go/gnav_store_en_us)
Adobe Store (www.adobe.comhttp://www.adobe.com/go/gnavtray_store_en_us) for home and home ofce
Education Store (www.adobe.comhttp://www.adobe.com/go/gnavtray_store_education_en_us) for students, educators, and staff
Business Store (www.adobe.comhttp://www.adobe.com/go/gnavtray_store_business_en_us) for small and medium businesses
Other ways to buy (www.adobe.comhttp://www.adobe.com/go/gnavtray_store_otherwaystobuy_en_us)
Sample Queries
These samples are given in Java properties style notation. To use them with the Java API, use a Java HashMapas in
the API sample that follows.
For the QueryBuilderJSON Servlet, each example includes a link to your local CQ installation (at the default
location, http://localhost:4502). Note that you have to log in to your CQ instance before using these links.
NOTE
To view the returned JSON data in your browser you may want to use a plugin such as
JSONView for Firefox.
By default, the query builder json servlet displays 10 hits. Adding the parameter of
p.limit=-1 allows the servlet to show the entire query result.
type=nt:file
nodename=*.jar
orderby=@jcr:content/jcr:lastModified
orderby.sort=desc
Code samples are intended for illustration purposes only.
type=cq:Page
orderby=@jcr:content/cq:lastModified
Code samples are intended for illustration purposes only.
https://docs.adobe.com/docs/en/cq/5-6-1/dam/customizing_and_extendingcq5dam/query_builder.html
1/6
4/5/2016
type=cq:Page
orderby=@jcr:content/cq:lastModified
orderby.sort=desc
Code samples are intended for illustration purposes only.
fulltext=Management
orderby=@jcr:score
orderby.sort=desc
Code samples are intended for illustration purposes only.
type=cq:Page
tagid=marketing:interest/product
tagid.property=jcr:content/cq:tags
Code samples are intended for illustration purposes only.
Use the tagidpredicate as in the example if you know the explicit tag ID.
Use the tagpredicate for the tag title path (without spaces).
Because, in the previous example, you are searching for pages (cq:Pagenodes), you need to use the relative path
from that node for the tagid.propertypredicate, which is jcr:content/cq:tags. By default, the
tagid.propertywould simply be cq:tags.
fulltext=Management
group.p.or=true
group.1_path=/content/geometrixx/en/company/management
group.2_path=/content/geometrixx/en/company/bod
Code samples are intended for illustration purposes only.
This query uses a group (named "group"), which acts to delimit subexpressions within a query, much as parentheses
do in more standard notations. For example, the previous query might be expressed in a more familiar style as:
"Management" and ("/content/geometrixx/en/company/management" or
"/content/geometrixx/en/company/bod")
Inside the group in the example, the pathpredicate is used multiple times. To dierentiate and order the two instances
of the predicate(ordering is required for some predicates), you must prex the predicates with N_ where N is the
ordering index. In the previous example, the resulting predicates are 1_pathand 2_path.
The pin p.oris a special delimiter indicating that what follows (in this case an or) is a parameter of the group, as
opposed to a subpredicate of the group, such as 1_path.
If no p.oris given then all predicates are ANDed together, that is, each result must satisfy all predicates.
NOTE
You cannot use the same numeric prex in one single query, even for dierent predicates.
type=cq:PageContent
property=cq:template
property.value=/apps/geometrixx/templates/homepage
Code samples are intended for illustration purposes only.
This has the drawback that the jcr:contentnodes of the pages, not the pages themselves, are returned. To solve
this, you can search by relative path:
http://localhost:4502/bin/querybuilder.json?
property=jcr%3acontent%2fcq%3atemplate&property.value=%2fapps%2fgeometrixx%2ftemplates%2fhomepage&type=cq%3aPage
(www.adobe.comhttp://localhost:4502/bin/querybuilder.json?
property=jcr%3acontent%2fcq%3atemplate&property.value=%2fapps%2fgeometrixx%2ftemplates%2fhomepage&type=cq%3aPage)
1
2
type=cq:Page
property=jcr:content/cq:template
property.value=/apps/geometrixx/templates/homepage
https://docs.adobe.com/docs/en/cq/5-6-1/dam/customizing_and_extendingcq5dam/query_builder.html
2/6
4/5/2016
property.value=/apps/geometrixx/templates/homepage
Code samples are intended for illustration purposes only.
http://localhost:4502/bin/querybuilder.json?
1_property=jcr%3acontent%2fcq%3atemplate&1_property.value=%2fapps%2fgeometrixx%2ftemplates%2fhomepage&2_property=jcr%3acontent%2fjcr%3atitle&2_property.
(www.adobe.comhttp://localhost:4502/bin/querybuilder.json?
1_property=jcr%3acontent%2fcq%3atemplate&1_property.value=%2fapps%2fgeometrixx%2ftemplates%2fhomepage&2_property=jcr%3acontent%2fjcr%3atitle&2_property.
1
2
3
4
5
type=cq:Page
1_property=jcr:content/cq:template
1_property.value=/apps/geometrixx/templates/homepage
2_property=jcr:content/jcr:title
2_property.value=English
Code samples are intended for illustration purposes only.
property=jcr:title
property.1_value=Products
property.2_value=Square
property.3_value=Events
Code samples are intended for illustration purposes only.
For multi-value properties, you can also require that multiple values match ("A" and "B" and "C"):
http://localhost:4502/bin/querybuilder.json?
property=jcr%3atitle&property.and=true&property.1_value=test&property.2_value=foo&property.3_value=bar
(www.adobe.comhttp://localhost:4502/bin/querybuilder.json?
property=jcr%3atitle&property.and=true&property.1_value=test&property.2_value=foo&property.3_value=bar)
1
2
3
4
5
property=jcr:title
property.and=true
property.1_value=test
property.2_value=foo
property.3_value=bar
Code samples are intended for illustration purposes only.
1
2
3
property=jcr:title
property.value=Triangle
p.hits=full
Code samples are intended for illustration purposes only.
Use p.hits=selectiveand specify the properties you want to get in p.properties, separated by a space:
http://localhost:4502/bin/querybuilder.json?
p.hits=selective&p.properties=sling%3aresourceType%20jcr%3aprimaryType&property=jcr%3atitle&property.value=Triangle
(www.adobe.comhttp://localhost:4502/bin/querybuilder.json?
p.hits=selective&p.properties=sling%3aresourceType%20jcr%3aprimaryType&property=jcr%3atitle&property.value=Triangle)
1
2
3
4
property=jcr:title
property.value=Triangle
p.hits=selective
p.properties=sling:resourceTypejcr:primaryType
Code samples are intended for illustration purposes only.
Another thing you can do is include child nodes in the QueryBuilderresponse. In order to do this you need to
specify p.nodedepth=n, where n is the number of levels you want the query to return. Note that, in order for a child
node to be returned, it must be specied by the properties selector (p.hits=full). Example:
http://localhost:4502/bin/querybuilder.json?
p.hits=full&p.nodedepth=5&property=jcr%3atitle&property.value=Triangle
(www.adobe.comhttp://localhost:4502/bin/querybuilder.json?
p.hits=full&p.nodedepth=5&property=jcr%3atitle&property.value=Triangle)
1
2
3
4
property=jcr:title
property.value=Triangle
p.hits=full
p.nodedepth=5
Code samples are intended for illustration purposes only.
More Predicates
For more predicates, see the Javadoc for the*PredicateEvaluatorclasses (www.adobe.com/docs/en/cq/5-61/javadoc/com/day/cq/search/eval/PredicateEvaluator.html) . The Javadoc for these classes contains the list of
https://docs.adobe.com/docs/en/cq/5-6-1/dam/customizing_and_extendingcq5dam/query_builder.html
3/6
4/5/2016
StringfulltextSearchTerm="Geometrixx"
Map<String,String>map=newHashMap<String,String>()
map.put("path","/content")
map.put("type","cq:Page")
map.put("group.p.or","true")
map.put("group.1_fulltext",fulltextSearchTerm)
map.put("group.1_fulltext.relPath","jcr:content")
map.put("group.2_fulltext",fulltextSearchTerm)
map.put("group.2_fulltext.relPath","jcr:content/@cq:tags")
map.put("p.offset","0")
map.put("p.limit","20")
Queryquery=builder.createQuery(PredicateGroup.create(map),session)
query.setStart(0)
query.setHitsPerPage(20)
SearchResultresult=query.getResult()
inthitsPerPage=result.getHits().size()
longtotalMatches=result.getTotalMatches()
longoffset=result.getStartIndex()
longnumberOfPages=totalMatches/20
DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance()
DocumentBuilderbuilder=factory.newDocumentBuilder()
Documentdoc=builder.newDocument()
Elementroot=doc.createElement("results")
doc.appendChild(root)
for(Hithit:result.getHits()){
Stringpath=hit.getPath()
Elementresultel=doc.createElement("result")
root.appendChild(resultel)
Elementpathel=doc.createElement("path")
pathel.appendChild(doc.createTextNode(path))
resultel.appendChild(pathel)
}
Code samples are intended for illustration purposes only.
NOTE
To learn how to build an OSGi bundle that uses the QueryBuilder API and use that OSGi bundle
within an Adobe Experience Manager application, see Creating Adobe CQ OSGi bundles that
use the Query Builder API.
The same query executed over HTTP using the Query Builder (JSON) Servlet:
http://localhost:4502/bin/querybuilder.json?
path=/content&type=cq:Page&group.p.or=true&group.1_fulltext=Geometrixx&group.1_fulltext.relPath=jcr:content&group.2_fulltext=Geometrixx&group.2_fulltext
(www.adobe.comhttp://localhost:4502/bin/querybuilder.json?
path=/content&type=cq:Page&group.p.or=true&group.1_fulltext=Geometrixx&group.1_fulltext.relPath=jcr:content&group.2_fulltext=Geometrixx&group.2_fulltext.relPath=jcr:content/@cq:tags&p.oset=0&p.li
voidstoreQuery(Queryquery,Stringpath,booleancreateFile,Sessionsession)throws
Code samples are intended for illustration purposes only.
builder.storeQuery(query,"/mypath/getfiles",true,session)
Code samples are intended for illustration purposes only.
Any previously stored queries can be loaded from the repository by using the QueryBuilder#loadQuery
(www.adobe.comhttp://dev.day.com/docs/en/cq/5-61/javadoc/com/day/cq/search/QueryBuilder.html#loadQuery(java.lang.String,%20javax.jcr.Session))
method:
https://docs.adobe.com/docs/en/cq/5-6-1/dam/customizing_and_extendingcq5dam/query_builder.html
4/6
4/5/2016
QueryloadQuery(Stringpath,Sessionsession)throwsRepositoryException,IOException
Code samples are intended for illustration purposes only.
For example, a Querystored to the path /mypath/getfilescan be loaded by the following snippet:
1
QueryloadedQuery=builder.loadQuery("/mypath/getfiles",session)
Code samples are intended for illustration purposes only.
The log output (INFO level) of the query builder implementation when executing the query described in Testing and
Debugging:
1
2
3
4
5
6
7
8
9
10
11
12
com.day.cq.search.impl.builder.QueryImplexecutingquery(predicatetree):
null=group:limit=20,offset=0[
{group=group:or=true[
{1_fulltext=fulltext:fulltext=Geometrixx,relPath=jcr:content}
{2_fulltext=fulltext:fulltext=Geometrixx,relPath=jcr:content/@cq:tags}
]}
{path=path:path=/content}
{type=type:type=cq:Page}
]
com.day.cq.search.impl.builder.QueryImplXPathquery:/jcr:root/content//element(*,cq:Page)[(jcr:contains(jcr:content,"Geometrixx")orjcr:conta
com.day.cq.search.impl.builder.QueryImplnofilteringpredicates
com.day.cq.search.impl.builder.QueryImplqueryexecutiontook69ms
Code samples are intended for illustration purposes only.
If you have a query using predicate evaluators that lter or that use a custom order by comparator, this will also be
noted in the query:
1
2
3
4
5
6
7
8
9
10
com.day.cq.search.impl.builder.QueryImplexecutingquery(predicatetree):
null=group:[
{nodename=nodename:nodename=*.jar}
{orderby=orderby:orderby=@jcr:content/jcr:lastModified}
{type=type:type=nt:file}
]
com.day.cq.search.impl.builder.QueryImplcustomorderbycomparator:jcr:content/jcr:lastModified
com.day.cq.search.impl.builder.QueryImplXPathquery://element(*,nt:file)
com.day.cq.search.impl.builder.QueryImplfilteringpredicates:{nodename=nodename:nodename=*.jar}
com.day.cq.search.impl.builder.QueryImplqueryexecutiontook272ms
Code samples are intended for illustration purposes only.
Javadoc Links
Javadoc
Description
com.day.cq.search (www.adobe.com/docs/en/cq/5-61/javadoc/com/day/cq/search/package-summary.html)
com.day.cq.search.result (www.adobe.com/docs/en/cq/5-61/javadoc/com/day/cq/search/result/package-summary.html)
Result API
com.day.cq.search.facets (www.adobe.com/docs/en/cq/5-61/javadoc/com/day/cq/search/facets/package-summary.html)
Facets
com.day.cq.search.facets.buckets (www.adobe.com/docs/en/cq/5-61/javadoc/com/day/cq/search/facets/buckets/package-summary.html)
com.day.cq.search.eval (www.adobe.com/docs/en/cq/5-61/javadoc/com/day/cq/search/eval/package-summary.html)
Predicate Evaluators
com.day.cq.search.facets.extractors (www.adobe.com/docs/en/cq/56-1/javadoc/com/day/cq/search/facets/extractors/packagesummary.html)
com.day.cq.search.writer (www.adobe.com/docs/en/cq/5-61/javadoc/com/day/cq/search/writer/package-summary.html)
https://docs.adobe.com/docs/en/cq/5-6-1/dam/customizing_and_extendingcq5dam/query_builder.html
5/6
4/5/2016
(www.adobe.comhttp://www.adobe.com/go/gfooter_truste_logo)
Copyright 2009-2016 Adobe Systems Incorporated. All rights reserved.
Use of this website signies your agreement to the Terms of Use (www.adobe.comhttp://www.adobe.com/go/gfooter_terms_of_use) and Online Privacy Policy
(www.adobe.comhttp://www.adobe.com/go/gfooter_privacy_policy) .
https://docs.adobe.com/docs/en/cq/5-6-1/dam/customizing_and_extendingcq5dam/query_builder.html
6/6