Cq5 Querybuilder: .Adaptto (Berlin)
Cq5 Querybuilder: .Adaptto (Berlin)
Cq5 Querybuilder: .Adaptto (Berlin)
adaptTo(Berlin)
CQ5 QueryBuilder
Alexander Klimetschek | Senior Developer, Day | @alexkli
Agenda
(1) What it looks like & Use Cases
(2) Philosophy & Consequences
(3) Debugging
(4) Queries & Samples
(5) Running Queries
(6) Facets
(7) Extending
As URL:
http://localhost:4502/bin/querybuilder.json?
type=nt:file&nodename=*.jar&
orderby=@jcr:content/jcr:lastModified&orderby.sort=desc
Result as JSON:
{
success: true,
results: 10,
total: 155,
offset: 0,
hits: [{
path: "/apps/cloudmgr/install/cq-change-admin-pwd-1.0.1-SNAPSHOT.jar"
excerpt: "application/java-archive"
name: "cq-change-admin-pwd-1.0.1-SNAPSHOT.jar"
....
},{...}
]
}
Use Cases!?
form-based elements
querybuilder UI components
Philosophy
QueryBuilder is...
easily extensible
QueryBuilder is not...
or even cache
ld
i
u
b
ry
que
/
n
i
/b
2
ed
&
0
i
r
5
f
a
4
i
j
:
*.
st
Mod
=
o
t
e
h
s
m
l
a
a
oca noden /jcr:l
l
/
/
&
:
t
http nt:file :conten
=
type by=@jcr
r
orde
er
More Consequences
checked: field=on
Copy/paste
obvious one, but XPath for JCR does not respect it (limit & oset)
Extensible
QueryBuilder Debugger
http://localhost:4502/libs/cq/search/content/querydebug.html
Debug logs
Anatomy of a query
Predicate name and type and parameter
Predicates
type=cq:Page
property=jcr:content/cq:template
property.value=/apps/geometrixx/templates/homepage
Parameter
Value
10
Handles:
filtering of results
facet extraction
11
Name = <nr>_<type>
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
12
Standard predicates
path
language
property
page languages
event
JCR property
calendar
dierent operations
type
node type
fulltext
range
daterange
similar
rep:similar
13
Ordering
orderby=@cq:tags
orderby=@jcr:content/cq:tags
orderby=1_property
Multiple orderings
1_orderby=@cq:tags
2_orderby=@cq:lastModified
3_orderby=nodename
14
Grouping of predicates
Like brackets:
Nested:
fulltext=Management
group.p.or=true
group.1_group.path=/content/geometrixx/en
!
e
r
group.1_group.type=cq:Page
a
Be w e s l o w !
group.2_group.path=/content/dam/geometrixx C a n b
group.2_group.type=dam:Asset
15
Running queries
Default servlets
JSON: http://localhost:4502/bin/querybuilder.json
iCalendar: http://localhost:4502/bin/querybuilder.ics
Java API
PredicateGroup root = PredicateGroup.create(request.getParameterMap());
Query query = queryBuilder.createQuery(root, session);
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
String path = hit.getPath();
// ....
}
16
JSON servlet
JSON: http://localhost:4502/bin/querybuilder.json
simple
full
selective
17
Java API
From predicates:
PredicateGroup group = new PredicateGroup();
group.add(new Predicate("mypath", "path").set("path", "/content"));
group.add(new Predicate("mytype", "type").set("type", "nt:file"));
Query query = builder.createQuery(group, session);
18
Persisted Queries
Store query
in the repository
as file node
or as string property
Query query = .... // create query normally
// store query as file
queryBuilder.storeQuery(query, /content/myquery, true, session);
// load it again
Query query = queryBuilder.loadQuery(/content/myquery, session);
19
Facets
Facet = tag
Facet = daterange
20
Simple as that:
String bucketURL =
query.refine(bucket).getPredicates().toURL();
21
22
PropertyFacetExtractor
DistinctValuesFacetExtractor
PredefinedBucketsFacetExtractor
23
Documentation
http://wem.help.adobe.com/enterprise/en_US/10-0/wem/dam/
customizing_and_extendingcq5dam/query_builder.html
Javadocs
http://wem.help.adobe.com/enterprise/en_US/10-0/wem/javadoc/com/day/cq/search/
package-summary.html
24