Skip to main content

Search Filters

The 'Search Filters' Web Part allows to filter the results displayed in a connected 'Search Results' Web Part.

Connection with search results

Two-ways connection

Connection between search filters and search results is always a two-ways connection meaning both web parts need to be configured.

  1. Edit the page and add a 'PnP Modern Search Core Components - Search Results' and a 'PnP Modern Search Core Components - Search Filters' web parts.

    PnP Modern Search Core Components Search Filters WebPart

    PnP Modern Search Core Components Search Filters WebPart default

  2. In the filters web part

    • In the property pane settings ➝ Get filter values from these Web Parts ➝ Select the search results web part to filter:

    Filters connection

    Multiple connected search results

    You can connect multiple search results web parts to a single search filters one. In this case, filter values results and counts coming from connected search results having the same field name will be merged together. Other fields will be displayed as separate entries in the filters bar.

    Example:

    Search results WebPart1 and WebPart2 expose respectively a 'FileType' filter with values and counts value1 (1),value2 (1) for WebPart1 and value2 (1), value3 (1) for WebPart2 and both are connected to the filters Web Part. In this case, a single 'FileType' filter name will be displayed (because the filter name is the same) with values value1 (1),value2 (2),value3 (1). If you select a value that is not present in a search results (ex: value1 for search results WebPart2), you will simply get zero result.

    • Choose operator to use between filters (AND/OR). 'OR' by default.

    Filters connection

    Add new filters

    tip

    You can change filters order in the filters bar using drag n' drop in the property pane.

  3. In the search results web part

    • In the property pane settings ➝ enable Use filters/sort option.
    • Then Get filters configuration from this Web Part ➝ Select the search filters web part to connect:

Default value

Configure filters

Configure the basic options for a specific filter.

SettingDescription
Filter NameThe field name from the search schema (ex: RefinableStringXXX)

warning
For a field to be used as filter, it has be Refinable in the search schema.
Display nameThe name of the filter to display for users. You can specify a value per language according to your site language settings.

info
If your site is configured to use multiple languages, the 'Add new translation' button will be available. Otherwise, the default language is used by default and the button is greyed out.
TemplateThe template to use to display filter values. The builtin templates are:
  • Check box ➝ use it for Text properties (ex: RefinableStringXXX)

    Check box

  • Date range ➝ use it for Datetime properties (ex: RefinableDateXXX)

    Date range

Show countIf applicable for the selected template, display counts for each filter values.
OperatorIf multi values is selected, the operator to use between values (OR/AND).
Mutli valuesIf applicable for the selected template, allow selection of multiple values.
Sort bySort values by name or by count.
Sort directionSort values in ascending/descending order.
Number of valuesThe maximum number of values to be retrieved and display for a given filter. This value is useful if you use SharePoint refiners with a lot of refiner values. Default is 50, maximum is 10000. To get all refiner values, you must specify an higher number manually. May have an impact on performances.

Filter options

Control filter visibility with search verticals

Connection with search verticals allows you to configure visibility for each individual filters. This allows to have only one search filters web part on the page connected to multiple search results web parts.

  1. Edit the page and add a 'PnP Modern Search Core Components - Search Verticals'. Configure some verticals.

    Filter display

  2. In the filters web part ➝ enable Use verticals option.

  3. Then Search verticals component to connect to ➝ select search verticals web part to connect.

Find Web Part instance ID

To find the Web Part instance ID ➝ here

  1. For each individual filter, a new configuration tab 'Display' is available. Select the tab where the current filter should be displayed:

    Filter display

warning

If you worked with the PnP Modern Search in the past, the search verticals behavior is different here. In PnP Modern Search, connected search verticals controls the visiblity of the entire web part. In this web part, visibility is controlled per filter.

Customize templates

Working with templates

To know how to author templates, refer to the general guidelines.

The search filters web part provides the following templates to be overriden:

filter-name

This template controls the rendering of the filter name:

➝ Applies to filter templates: Checkbox, Date

Properties

The following properties can be used in the template:

PropertyDescription
nameThe filter display name (localized).
filterNameThe filter field name.
submittedValuesArray of submitted values.
<template data-type="filter-name">
{{ name.toUpperCase() }}
</template>

Filter name template

filter-value

This template controls the rendering of each individual filter values.

➝ Applies to filter templates: Checkbox, Date

Properties

The following properties can be used in the template:

PropertyDescription
keyAn unique identifier for that filter value.
nameThe filter value display name.
valueInternal value to use when the value is selected.
operatorThe comparison operator to use with this value.
valueInternal value to use when the value is selected
countThe number of results with this value.
keywordsThe current search keywords associated to the search.
filterNameThe filter field name where the value belongs.
<template data-type="filter-value">

<div data-highlight="" data-if="filterName === 'FileType'">
{{ name.toUpperCase() }}
</div>
<div data-else="">
{{ name }}
</div>

</template>

Filter value  template

tip

You can apply a template conditionally to a filter name using data-if="filterName === 'FileType'". Use the debug mode to inspect variables that can be used in your templates.