Writing a query and fetching results

November 14, 2023

Getting started

Augmented Search queries are based on GraphQL. This section explains how to build such queries and how to fetch results. 

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.

To make it easier to build queries, we recommend using GraphQL playground available in Developer Tools > GraphQL or in the Jahia tools. It is also the best place to find documentation about the Augmented Search API (as GraphQL supports introspection), which is easily accessible on the right side of the GraphQL playground:

AS-GraphQLPlayground.png

Search arguments

Several arguments are available to build your search query. Only the q argument is mandatory, if the other arguments are not passed, then their corresponding default value will be used.

The following example shows to fill the search arguments. This query only returns the number of matching results. See the Results section below to find out what information can be requested for each search result.

query {
  search(
    q: "searched terms"
    language: "en"
    siteKeys: ["mySite1","mySite2"]
    searchIn: [CONTENT, FILES]
    workspace: LIVE
  ) {
    results{
      totalHits
    }
  }
}
Argument Description Default value / behavior
q (mandatory) The searched terms -
siteKeys Search in the provide list of sites (provide the site key)
Search in all sites if left empty
Searches in all site (empty)
language Language to search in. Use the ISO format for the language, e.g. "EN" or "FR". EN
workspace Specify if searching in LIVE (published content) or EDIT (staging content) LIVE
searchIn Speicify if searching for CONTENT and/or FILES Searches both content and files
filters

Using filters allow you to narrow the search results based on the indexed properties.

Consult the filtering doc

-

Results parameters

The following query searches for "search terms" using the default search parameters (see above). This query uses pagination, and will return the first page with 10 results, ordered by the page system name value in alphabetical order. For each search result, it will return all the default available fields, and the systemname property. On top of that, it will provide the total number of search results, and the time taken to execute the query.

query {
  search(
    q: "searched terms"

  ) {
    results(
      page: 0
      size: 10
      sortBy: { dir: ASC, field: "jgql:systemName" }
    ) {
      hits {
        displayableName
        created
        createdBy
        excerpt
        id
        keywords
        link
        mimeType
        nodeType
        path
        property (name:"jgql:systemName") 
        score
        tags
      }
      totalHits
      hasMore
      took
      hitsOnPage
    }
  }
}

hits

For each search result, the following properties are available:

Property name Description
created Date when the page/content/file was created
createdBy User who created the page/content/file
displayableName Prettified displayable name of the page/content/file
excerpt Short extract from the hit. The searched terms present in the excerpt can be highlighted (see the Highlighting page)
id UUID of the page/content/file
keywords Keywords associated with this hit
lastModified Date and time of last modification
lastModifiedBy Last user who modified the page/content/file
lastPublished Date and time of last publication
lastPublishedBy Last user who published the page/content/file
link Formatted link to the page/content/file
mimeType Mime type of the page/content/file
nodeType Main type of the hit (e.g. jnt:page)
path Path of the page/content/file
property Fetch the value of the requested property, property name can be pass as an alias or as an argument
Example: property (name:"jgql:systemName")
score Determines how relevant a match is to the query
tags Tags associated with this hit

Facets

Facets are documented in the dedicated Facet section.