Tuesday, April 25, 2017

AEM 6 QueryBuilder API in brief

AEM 6 QueryBuilder API in brief

Base Path :

http://host:port/bin/querybuilder.json

The query parameters are added after this path in order to search for specific results.

Parameters can be :

path
The path in content repository where you want to search for the results

p.limit(=number)
To limit the parameters. Setting p.limit=-1 will give all the possible results.

p.guessTotal(=true/false or number)
This parameter should be used with large number of result set. When set to true, the query builder returns the appropriate results on the basis of the value of p.offset and p.limit. 
the actual total number of results might not be visible to the user but the minimum number of results will be visible as total number which is the value of this parameter if it is set as number.

type(=cq type of the node like cq:File, nt:unstructured)
Node type of the crx node

nodename(=anystring)
Name of the node. This can accept wild card value like *.jar

orderby(=pathToNodeOrProperty)
This parameter can take node as well as propery to order the results. i.e.
orderby=@jcr:content/cq:lastModified

You can also provide the sorting order like
orderby.sort=desc/asc 

By default it is ascending order

fulltext(=anystring)
To perform a full text search in name, title and path

tagid=(IdOfTheTag)
To search for the pages with specific tag. Also, this can have filter on property as follows.
tagid.property=jcr:content/cq:tags
By default tagid.property will be cq:tags

tag=(titleOfTag)
To search on the basis of tag name

Searching at Multiple Paths
You can add multiple paths as follows
group.1_path=/content/abc
group.a_path=/content/xyz

By default the value of operator here will be add. This can be changed by setting the value of p.or=true which will make sure the search result is present in 1_path or 2_path

property(=nameOfProperty)
Search is performed on the basis of give property. If the property is existing the page, it will be added in the search results.
Additionally you can also provide the value of property as filter i.e.
property.value(=valueOfProperty)


Searching on Multiple Properties
You can search on multiple properties and values as follows. This will have and operation applied.
1_property=nameOfProperty1
1_property.value=valueOfProperty1
2_property=nameOfProperty2
2_property.value=valueOfProperty2


Also you can have multiple values to the property. Which will have or operation applied.
property=nameOfProperty
property.1_value=value1OfProperty
property.2_value=value2OfProperty

p.hits(=full/selective) 
The value full will mean all the properties of the searched pages will be returned and the value selective mean only the selected properties will be shown. i.e.
p.hits=selective
p.properties=jcr:path , jcr:title (Note the speace before and after comma )

p.nodepath(=number)
The number of level upto which the search should be performed. Considering path as the 0 level.

Debugging the query
For query debugging following link can be accessed from your instance of AEM

http://<host>:<port>/libs/cq/search/content/querydebug.html







No comments:

Post a Comment

Some more AEM 6 Interview Questions for Architects

 Some more AEM 6 Interview Questions for Architects 1. Consider you have a workflow with two steps. One step is to transfer the asset from s...