close

Filter

loading table of contents...

Headless Server Developer Manual / Version 2110

Table Of Contents

6.1 Generic Search

Search is handled with the searchServiceAdapter adapter. The following functionality is supported:

  • Full text search
  • Paging
  • Limit
  • Filter by content type, optionally including their sub types
  • Predefined sort fields with order
  • Limitation to a site
  • Valid from and valid to conditions are applied to search filters automatically

The following GraphQL query is a simple example for fetching a search result.

{
  content {
    search(query:"Perfect") {
      numFound
      result {
        name
      }
    }
  }
}
  

Several parameters can be passed to the SearchServiceAdapter to customize the search:

  • query: The search query.
  • offset: The offset.
  • limit: The limit of search result.
  • docTypes: Content types to restrict the search result.

    Misspelled content types and invalid content types will cause a graphql error in the response. When passing an abstract content type, the subtypes are retrieved, if the parameter includeSubTypes = true. Passing an abstract content type with includeSubTypes = false will also cause a graphql error. The search result does not contain abstract document types, only the concrete sub types.

  • sortFields: List of sort field with order, separated by '_', in upper case, for example, ID_ASC.

    The set of available sort fields in the schema is limited to the enum SortFieldWithOrder defined in the content schema: ID, DOCUMENTTYPE, TITLE, TEASER_TITLE, MODIFICATION_DATE, CREATION_DATE, EXTERNALLY_DISPLAYED_DATE. This enum can be extended in the schema by adding an available field with a sort order.

    The available fields are defined in SearchConstants#FIELDS: ID, DOCUMENTTYPE, NAVIGATION_PATHS, NOT_SEARCHABLE, SUBJECT_TAXONOMY, LOCATION_TAXONOMY, TITLE, TEASER_TITLE, TEASER_TEXT, KEYWORDS, MODIFICATION_DATE, CREATION_DATE, TEXTBODY, SEGMENT, COMMERCE_ITEMS, CONTEXTS, AUTHORS, HTML_DESCRIPTION, VALID_FROM, VALID_TO, EXTERNALLY_DISPLAYED_DATE

    To configure custom fields, a specific bean can be configured, see section below.

    Possible order field values: ASC, DESC

  • siteId: The siteId can be passed as parameter to restrict search per site.
  • includeSubTypes: A Boolean flag, indicating to include the sub types of the given doc types in the search. Defaults to 'false'.

The query parameter supports the following syntax:

  • The + and - characters are treated as "mandatory" and "prohibited" modifiers for terms.
  • Quoted expressions, like "Foo Bar" are treated as a phrase
  • An odd number of quote characters is evaluated as if there were no quote characters at all.
  • The wildcard character '*' supports the search for partial terms like 'frag*', which would find, for example, the terms 'fragment' and 'fragile' as well. When used exclusively as a search query, the search is executed with all other search parameters but without an explicit search expression.

By default, the SearchServiceAdapter uses the caeSolrQueryBuilder Spring bean, which in turn invokes searches on Solr on the cmdismax endpoint. For details, see Section 3.8.1, “Details of Language Processing Steps” in Search Manual.

The used endpoint can be customized in HeadlessSearchConfiguration. See section customization at the end of this chapter for details.

The following GraphQL query is a more complex example for fetching a search result.

{
  content {
    search(query: "Perfect", offset: 3, limit: 5, docTypes: ["CMArticle", "CMPicture"], sortFields: [CREATION_DATE_ASC, MODIFICATION_DATE_ASC], siteId: "abffe57734feeee", includeSubTypes: true) {
      numFound
      result {
        name
        type
      }
    }
  }
}

  

If docTypes or limit is not passed as parameter, the following search configuration is taken into account, which is read from CMS content using settings. See general search configuration for details in Blueprint Developer Manual .

  • searchDoctypeSelect, search.doctypeselect: document types to restrict the search result
  • searchResultHitsPerPage, search.result.hitsPerPage: limit of the search result

Valid from and valid to conditions are applied to search filters automatically.

Configuration of custom SOLR fields

To configure a custom field of the SOLR index, a bean with qualifier customSolrFields can be added to the Spring context.

This bean of type Map<String, String> contains the custom field's name as a constant accessor and the field name in the SOLR index, e.g. TITLE, title.

This custom field can then be used, e.g. to apply a sort order.

The customSolrFields are applied to the SolrQueryBuilder.

The default SOLR fields are defined in the class SearchConstants, these are the default fields of the SOLR CAE index.

Generic configuration

The connection to Solr is defined with solr.url

The search index is specified with property caas.search.solr.collection

Caching is only performed in live mode and can be configured with caas.search.cache.seconds

Configuration of a custom index

If search should be performed on a custom SOLR index, the SolrQueryBuilder must be extended and configured. The following constructor arguments can be passed:

  • searchHandler: the search handler, e.g. /cmdismax
  • filterQueryDefinitionMap: a map containing filter query definitions to be used by custom filter queries
  • customFields: custom fields of the SOLR index as map containing the field name and the SOLR field name, e.g. TITLE, title

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.