Fetching results

November 14, 2023

Typically, you use a search API to fetch results. In Augmented Search, this is done through the results node, available directly under search.


query {
  search(
    q: "jahia"
  ) {
    results {
      hits {
        displayableName
      }
      totalHits
    }
  }
}

Pagination and sorting

In Augmented Search, pagination and sorting are defined through parameters under the results node (with default values detailed in the GraphQL schema), as shown in the example below.


query {
  search(
    q: "jahia"
    language: "en"
    siteKeys: ["digitall"]
    searchIn: CONTENT
    workspace: LIVE
  ) {
    results(
      page: 0
      size: 10
      sortBy: { dir: ASC, field: "jcr:title.keyword" }
    ) {
      hits {
        displayableName
      }
      totalHits
    }
  }
}

For pagination, the page parameter corresponds to the page count starting at 0. size specifies the number of documents to fetch for each page. You can see also the totalHits node, which returns the total number of documents within the search dataset. 

For sorting, parameters define the direction of sorting (ASC for Ascending, DESC for descending) and the field to perform sorting on. If no sorting information is provided, the Elasticsearch score is used to sort.

Individual results

Located under results, the hits node provides direct access to documents properties retrieved from Elasticsearch.


query {
  search(
    q: "jahia"
  ) {
    results {
      hits {
        id
        displayableName
        nodePath: property(name: "jgql:nodePath")
        originSite: property(name: "jgql:originSite")
      }
      totalHits
    }
  }
}


Available nodes are detailed in the schema. Note that you can also use the property node to retrieve a particular Elasticsearch field.