Written by The Jahia Team
 
Developers
   Estimated reading time:

Augmented Search 3.0 will introduce an improved GraphQL structure for search with a new schema. To help you discover this new schema and to ensure an easer migration, the new search nodes are being made available in Augmented Search 2.2.0 (and 1.3.0 for Jahia 7.X) and can be used in parallel with the other search nodes documented in other sections of the Academy.

Writing a search query

You can start writing your first search query by simply specifying a search term. The query contains two important levels:

  • search
    Defines a dataset that can be further operated on through provided parameters (most of which are optional). 
  • results
    Provides access to the actual search hits, with parameters related to pagination or sorting, to progressively retrieve search results.

The following example returns search results matching news across all of the indexed content.

{
  search(q: "news") {
    results {
      took
      hits {
        displayableName
      }
    }
  }
}

Search Node

Attached directly to the schema's root, the search node supports the following parameters:

  • q
    The query string. Can be left empty to support exploratory use cases.
  • siteKeys
    An array of site keys to search across. If not provided, search is performed in Jahia's default site.
  • language
    Language to search in. If not provided, search is performed in the platform language.
  • workspace
    The workspace to search in (LIVE or EDIT). If not provided, search is performed in LIVE.
  • searchIn
    The type of content to search by (CONTENT, FILES or both). If not provided, search is performed in both CONTENT and FILES.
  • filters
    Allows users to specify a search filter, for example, filtering by author.

Results

Starting from the dataset defined in the search node, the results node is used to retrieve actual results and supports the following parameters:

  • page
    Used for pagination, the page count to offset the results window (for example, display results starting in page 3). If not provided, displays results starting from page 0.
  • size
    Used for pagination, the number of documents to retrieve for the current page. If not provided, returns 25 documents.
  • sortBy
    Field and direction to return documents. If a direction is not provided, defaults to ASC (ascending).

Accessing the JCR

The previous version of the GraphQL schema provided direct access to the JCR form search results. Accessing nodes that are not indexed in Elasticsearch can have significant performance implications since each search result generates independent JCR calls to fetch additional data. This is also redundant with other features from our GraphQL API.

You can still access more details about search results from data in the JCR, but we recommend performing that through a subsequent GraphQL call. You can fetch the document UUID through Augmented Search hits and build a second GraphQL query like this:

query ($nodesArray: [String!]!) {
  jcr(workspace: LIVE) {
    nodesById(uuids: $nodesArray) {
      uuid
      product: property(name: "product") {
        refNodes {
          displayName
        }
      }
    }
  }
}

 

Using facets

The new search node supports three types of facets:

  • termFacet
    Returns aggregations based on a provided text field
  • numberRange
    Returns min/max values based on a provided numerical field
  • rangeFacet:
    Returns aggregation buckets based on provided ranges

Each facet is defined separately and can be used in parallel through aliases.

{
  search(q: "") {
    created: termFacet(field: "jgql:createdBy") {
      data {
        value
        count
      }
    }
    mimeType: termFacet(field: "jgql:mimeType.keyword") {
      data {
        value
        count
      }
    }    
  }
}