-
Templating and Integration Guide
- Part 1: Concepts
- Part 2: Modules
- Part 3: Templates and Studio
- Part 4: Content Definitions and Views
- Part 5: Advanced Techniques
- Part 6: Setting up an integration environment
- Part 7: Step by step integration
- Further reading and resources
Queries
The query language feature is actually a native functionality of a JCR-compliant implementation such as Apache Jackrabbit. It offers different query languages that are functionally equivalent, but differ in implementation and usage scenarios. It allows for complex condition matching and result ordering, as well as in some cases joins on multiple content object types. The result of the query is a list of matching nodes, ordered by the specified properties.
Here is an overview of the features offered by this type of querying:
- Search by content type (news, article, …)
- Complex conditions based on properties, or even in the case of SQL-2 or Query Object Model, joins may be used.
- Integration with faceted search
- Integration with front-end HTML caching
The following query languages are available:
- SQL- 2: Similar to the standard SQL database language so easy to use for developers. The queries are parsed and transformed into Java Query Object Model queries and then executed as such. As this is part of JCR v2, it is relatively new and does suffer from some youth in the implementation, notably on join performance. For most simple queries it will do fine, but for more complex ones it is recommended to use XPath until this query language implementation matures.
- JQOM (Java Query Object Model): this is a Java object representation of a JCR v2 query. It is possible to build these using Jahia’s provided query tag libraries, or to build them directly from Java code. SQL-2 and JQOM queries are quite similar, except that JQOM avoid the parsing stage, so they are a bit faster. In practice, it is quite seldom that JQOM is used, but it might be interesting in some cases.
- XPath: although it has been marked as deprecated in JCR v2, it is still available in Apache Jackrabbit and is by far the most optimized query language. It is not as easy to use as SQL-2 but it is very useful to build very fast queries and therefore often worth the extra effort in designing the query. There are some tricks to know on how to search for multi-language content as it is not handled transparently as in the case of the other two implementations, but even Jahia uses it internally for speed in the cases where SQL-2 performance is not fast enough.
Jahia also comes built-in with modules that use queries to provide their functionality. An example of this includes the “last news retrieval” feature in the news module. Also available is a generic “query” module that will ask for the query when added to a content page. This makes it easy for editors to be able to build custom queries at content creation time, without requiring any assistance from the integrators (of course this module should not be made available if this possibility is to be restricted).
Basic query syntax
To use the query tags in your scripts, you must reference the Query Taglib
<%@ taglib prefix="query" uri="http://www.jahia.org/tags/queryLib" %>
You find more information about the query tags here :http://www.jahia.com/community/documentation/jahiapedia/query/basics.html
Query built-in modules
Jahia comes with built-in modules to perform queries, which we are detailing here below:
- Content retrieval: retrieves a list of nodes based on their type, including with sorting and filtering criteria.
- Last News Retrieving: retrieves news items based on the creation date. The number of items as well as the category can be setup by the editor. If a category is set, only news categorized with this particular category will be retrieved. This component is used in the ACME demo package and is a good code sample for integrators.
- JCR Query: retrieve a list of items based on a hand made query (SQL-2 or XPath)

