Configuration

The Search API applies a default search configuration to all searches, using default values and filters.

Default Search configuration settings

The default search configuration is retrieved from a setting in M called SearchDefaults. The setting's name is a variable that is passed into the search-related API resources as a parameter called name. When a UI component performs a REST call, it looks up the setting in its configuration and passes it to the Search controller.

An example in Sitecore Content Hub is SearchConfiguration.json, which is in the PortalConfiguration section of the settings.

Warning

The API is configured to only load the related paths that are specified in a query. If you don't specify related path relations in your query, the response won't return any.

The search setting schema has the following properties.

Property

Description

Name

The name of the setting.

Take

The default number of results to return. This is only used if the search request does not include paging. By default, the maximum number of items per page is 50 and the maximum number of pages is 100.

Filters

The filters to apply to each query. If more than one filter is specified, they are evaluated together using AND operators.

Facets

The definitions used as facets. The schema determines how facets are linked to result-entities, for example using taxonomy relations.

Followups

Follow-up facet configuration. If a facet filter is applied for a certain definition, you can also append other facets to the search query.

PropertiesToLoad:

The properties that are included in the results.

relationsToLoad

The relations that are included in the results.

renditionsToLoad

The renditions to include in the results for entities that have renditions.

ResultTypes

The types of entities that are returned as results. Filters are added to the search query to make sure only entities of these types are returned.

SuperFacets

If a definition is flagged as a super facet in the configuration, the search response will contain additional information about that super facet.

Sorting

The default sorting method.

Facets

The simplest way to define a facet is to use the definition name. Facets depend on the Content Hub schema (for example, definitions being marked as IsTaxonomyItemDefinition).

There are two types of facets:

  • Normal facets (relations)

  • Field facets (properties)

Normal facet

RequestResponse
{
  "name": "M.Campaign"
}

Field facet

RequestResponse
{
  "name": "FileExtension",
  "type": 1
}

You can use the limit parameter to limit the number of values returned by the facet. The default value of this parameter is 10.

Note

Setting the limit parameter to 0 causes the facet to return all available values.

Each facet can be given a sorting parameter to determine how the items returned for that facet are ordered on the page. The potential values for this parameter are:

  • Count (default)

  • Alphabetical

  • Field

You can control the sort order of the facet by adding a direction parameter, which must be given a value of Ascending or Descending.

Note

Alphabetical sorting is only useful when all facet values are returned.

Filters

You can define filters using the JSON configuration setting or using the query contributor framework.

Each value expression used in the filter must resolve to a single Id.

It is also possible to create a filter of filters and choose which operator to apply for those inner filters.

Default filters using code

You can also apply filters using code.

This querycontributer allows you to directly influence the filters being applied on the query. These filters will not be visible on the client-side. (for example, querystring, querybuilder, and so on)

Once the querycontributer class is ready the next step is to register it in your project's ApplicationModule

RequestResponse
        public override void OnConfiguration(IContainer container)
        {
            base.OnConfiguration(container);

            IQueryConfiguration queryConfiguration = container.Resolve<IQueryConfiguration>();
            queryConfiguration.QueryContributorRegistry.Add<SearchConfigurationQueryContributor>("SearchConfiguration");
        }

You can combine multiple query contributors together with the filters from configuration. A query contributor is always tied to the name of the SearchConfiguration it should append the filters for.

Do you have some feedback for us?

If you have suggestions for improving this article,