Filtering

November 14, 2023

Augmented Search allows the search dataset to be filtered by passing various parameters to the search node. Different from the search string (the "q" parameter), this feature allows building more complex search criteria (for example, by date or by field value).

Using filter aliases

Augmented search provides access to a set of filter aliases to perform common filtering operations. The following aliases are available:

  • author
    The last user who published or modified the content
  • created, published, modified
    The date the selected operation was last performed
  • nodeType
    A node type to filter the dataset by
  • path
    The path of the document

Using aliases is particularly useful for simple queries, available parameters are detailed in the GraphQL schema. An alias can be used in conjunction with custom filters, in such cases, an "AND" operator is applied between those.

Using a custom filter

Custom filters allow for building complex querying logic and are particularly useful when users are presented with a search UI containing facets.

Custom filters work with any fields (jahia-native of custom properties) defined in your Elasticsearch schema, the only constraint being to make sure it matches the data types (for example, by only requesting numberRange filters on a numerical fields). 

Custom filters support three types of filters:

  • dateRange
    Filters documents based on a date field, for example, last published between Nov 2011 and Dec 2013)
  • numberRange
    Filters documents based on a number field
  • term
    Filters documents based on a text field value, for example, author is: JohnD

When used together an AND operator is applied between custom filters and values within custom filters.

dateRange filter

The dataRange filter allows for operation on date fields, using an array of ranges, as the simplified example below demonstrates.


query {
  search(
    q: "jahia"
    filters: {
      custom: {
        dateRange: [
          { ranges: [{ field: "jcr:lastPublished", after: "now-12y", before: "now-1M"  }] }
        ]
      }
    }
  ) {
    results {
      hits {
        displayableName
        lastPublished
      }
      totalHits
    }
  }
}


This allows the building of complex search experiences such as all documents:

  • Published until one month from now (date calculated at query time)
  • Published until December 2020 (fixed date)
  • Created between January 2019 and March 2020 AND published in April 2020

numberRange filter

The numberRange filter has a very similar behavior to dataRange, but operates on numbers instead of dates.

term filter

The term filter allows filtering based on field values, for example, all articles published by "root", as shown in the example below:


query {
  search(
    q: "jahia"
    filters: {
      custom: {
        term: [
          {terms: [{field: "jgql:createdBy", value: "root"}]}
        ]
      }
    }
  ) {
    results {
      hits {
        displayableName
        createdBy        
      }
      totalHits
    }
  }
}


 

Combining filters

All of the filters described here can be combined in a single query. In this case, the AND operator is used between filters.