Once you have Augmented Search installed and running, you can start writing your first queries. To make it easier we recommend getting started with GraphiQL available in Jahia tools.
Please note that for security reasons, the GraphQL API is closed even if nodes have public read permissions. For information on opening the API and making it usable for your application, see Setting up authorization.
This section shows you how how to create a basic query, and specify sort, basic and advanced filters, and facets options.
The section shows you how to create a basic query. The examples use the Digitall demo website that is bundled with Jahia.
A search query is composed of several parts:
searches
wrapper specifies siteKey, language and workspace properties and allows you to have multiple search queries which execute at the same time. Here’s an example of what the start of your query might look like.
{
jcr {
searches(siteKey: "digitall", language: "en", workspace: LIVE) {
...
}
}
}
q
which stands for query and is the only mandatory parameter. Here’s an example of using the q
parameter.
{
jcr {
searches(siteKey: "digitall", language: "en", workspace: LIVE) {
search(q:"news") {
took
totalHits
hasMore
hitsOnPage
hits {
node {
name
}
lastModified
lastPublished
lastModifiedBy
lastPublishedBy
displayableName
}
}
}
}
}
searchIn
parameter as shown below. By default (if you don’t provide a searchIn parameter), the search is performed in both files and content indices.
{
jcr {
searches(siteKey: "digitall", language: "en", workspace: LIVE) {
search(q:"news", searchIn:CONTENT) {
took
totalHits
hasMore
hitsOnPage
hits {
node {
name
}
lastModified
lastPublished
lastModifiedBy
lastPublishedBy
displayableName
}
}
}
}
}
{
jcr {
searches(siteKey: "digitall", language: "en", workspace: LIVE) {
search(
q:"news"
searchIn:[CONTENT]
limit:2
offset:0) {
took
totalHits
hitsOnPage
...
}
}
}
}
Now that you know how to write a basic text search query and use constraints, let’s look at some additional functionality which will help you refine your search further.
Sort just requires two ingredients: a property to sort on and a sorting direction. Here’s an example of adding sort on jcr:title to a query that sorts in descending order.
{
jcr {
searches(siteKey: "digitall", language: "en", workspace: LIVE) {
search(...
sortBy:{property:"jcr:title", orderType:DESC}) {
...
}
}
}
}