Reputation: 91
Why is there need of QueryBuilder API in AEM / CQ when we can use JCR Query API? What does it provide that the former doesn't? Or is it just a non-SQL alternative to JCR API? We are currently building a module which fetches info from JCR nodes and wanted to know the best way to go about it. Thank you.
Upvotes: 2
Views: 1795
Reputation: 3402
Query Builder is built on top of JCR Query API. What does query builder provide that JCR API doesn't ? IMHO it would be Usability. You deal with a map of predicates instead of queries. The Out of the box predicates work in most situations. The limit and offset features work like a charm for pagination situations. Grouping let's you write complex queries in a very readable manner. One more nice feature is the faceted search , your search results can be split by tags. Query Builder returns Resources and not nodes so you don't have to handle to deal with those checked repository exceptions that come along with JCR api ( https://cqdump.wordpress.com/2012/11/06/cq5-coding-patterns-sling-vs-jcr-part-1/ ).
Since it is exposed as a REST servlet it is often used in building interfaces like custom dashboards and the familiarity helps.
It's an abstraction so you are shielded from changes at lower level. Some of the queries that used to work in JackRabbit 2 don't work in the newer Oak (Aem 6) but all the query builder one's still work.
Faceted search example :
Query Builder Details : http://www.slideshare.net/alexkli/cq5-querybuilder-adapttoberlin-2011
Upvotes: 5