Using search filters

The Smart search filter web part allows users to limit the range of objects that will be searched (conditional filter), or define the order of the search results. You can connect any number of filters to the Smart search dialog or Smart search dialog with results.

The behavior of the smart search filter is primarily defined by the properties described below.

You can find information about the other properties by clicking the help link in the corner of the web part properties dialog.

Property

Description

Search dialog web part ID

Enter the Web part control ID of the Smart search dialog or Smart search dialog with results web part that you wish to connect to the filter.

Filter mode

Sets the user interface type of the filter. Possible choices are:

  • Drop-down list
  • Checkboxes
  • Radio buttons
  • Text box

Filter auto postback

Indicates whether the search results automatically refresh (via postback) whenever a user selects a different filtering option. Not applicable when using the text box Filter mode.

If you enable auto postback for a search filter, also set the Paging mode property to Postback for the related Smart search results or Smart search dialog with results web part.

Values

Determines the available filtering options. See the Defining filtering options section below for details.

Query name

Allows you to create the filtering options dynamically using a query (instead of the Values property). Enter the full code name of the query or Select a query. The query must return the appropriate values depending on the type of the filter.

For example, for a standard conditional filter, the query needs to load three columns in the following order: <index field name>,<value of the field>,<displayed text>

The following is a sample query that loads all document types as conditional filtering options:

SELECT TOP 1000 '+classname', ClassName, ClassDisplayName 
FROM CMS_Class 
WHERE ClassIsDocumentType = 1

Filter clause

Sets a clause that overrides the logical values specified for filtering options. Possible choices are:

  • None - no clause is added and the original logical values set for individual filtering options are used.
  • Must - indicates that the conditions in all filtering options must be fulfilled (adds the + symbol).
  • Must not - indicates that the conditions in all filtering options must not be fulfilled (adds the - symbol). Conditions are inverted compared to the Must option.

Filter is conditional

If true, the filter limits the scope of the objects that are searched (where condition). If false, the filter determines the order in which the search results are displayed (order by condition).

You can find examples of search filters on the sample Corporate Site on the Examples -> Web parts -> Full-text search -> Smart search -> Smart search filter and Faceted search pages.

 

On this page

Related pages

Defining filtering options

The most important part of configuring Smart search filter web parts is the definition of the filtering options offered to users. In most cases, you will set the options through the Values property of the web part. If you wish to use the Query name property to load the options dynamically, the rules described below also apply to the results retrieved by the query.

The format of the filtering options depends on the type of the filter.

Conditional filters

In the case of conditional filters, define one option per line in format:

Index field name;Value of the field;Displayed text

You need to specify the logical meaning of each filtering option by adding the + or - symbol as a prefix:

+The search only returns objects whose value in the field matches the value specified in the second part of the filtering option's definition.
-The search excludes all results whose value in the field matches the value specified in the second part of the filtering option's definition.

To create filtering options that check the values of multiple index fields, use the following syntax: (Field1:(Value1) OR Field2:(Value2));;Text

If you wish to use the same value for all fields in the condition clause, you can insert the value using the {0} expression: (Field1{0} OR Field2{0};Value;Text

When entering integer or double type fields as filter options, you need to specify the type of the value:

+DocumentCreatedByUserID;(int)53;Administrator

Examples:

  • ;;All
  • +classname;cms.smartphone;Smartphones
  • +_created;[{%ToSearchDateTime(CurrentDateTime.AddDays(-7))%} TO {%ToSearchDateTime(CurrentDateTime)%}];Past week
  • +_content;product;Results related to products
  • +(documenttags{0} OR _content{0});product;Results related to products
  • -(issecurednode:(true) OR requiresssl:((int)1));;Exclude secured documents

Search result order filters

When creating filters that change the order of the results (i.e. the Filter is conditional property is disabled), define options in the following format:

Index field name;;Displayed text

The order is determined according to the values in the specified field.

Notes:

  • By default, the order is ascending. To make the order descending, add the DESC keyword after the field name.
  • Use the ##SCORE## macro instead of the field name to order results according to their search relevance (the score order is always descending and cannot be reversed).

Examples:

  • ##SCORE##;;Score
  • documentcreatedwhen;;Creation date
  • SKUPrice DESC;;Price descending

Text box filter mode

Text box filters do not offer any selection options, so the Values property instead determines which index fields the system searches when a user enters an expression into the text box. You can specify multiple fields, each one on a new line. Like with standard conditional filters, the + and - symbols determine whether the search returns results that contain the text box value in the given field, or only those that do not.

For example, if a text box filter has +DocumentTags in the Values definition, visitors can enter the names of document tags into the text box and perform a standard search. The filter modifies the retrieved results to contain only documents that are marked by the specified tags.

Use the following syntax to create OR conditions that are fulfilled if the text box value matches at least one of multiple fields: (Field1{0} OR Field2{0})

For example: +(DocumentTags{0} OR _content{0})

The {0} expression represents the value that users type into the text box filter. The search internally converts the expression to Field:(value) in the resulting condition.

Tip: To create a text box filter that behaves like a regular search box, use +_content as the only field name.

You can also use text box filters to determine the order of the search results. In this case, disable the filter web part's Filter is conditional property and leave the Values property empty. Users can then enter the name of the field used for ordering into the text box. This scenario is not recommended for use by regular visitors on the live site.

In order for the filter to work correctly, the data fields used in the option definitions must be set as Searchable in the smart search field configuration of the given object type.

You can also create filtering options for the fields that are marked as Content by using _content as the field name. Such conditions are fulfilled if the value is found in any of the content fields.

Filtering without search text (Faceted search)

You can implement a faceted search based exclusively on filters. Faceted search allows users to get search results simply by selecting filtering options, without the need to enter and submit search text. To achieve this result, Configure the properties of the web part that you use to display search results (Smart search results or Smart search dialog with results) according to the following instructions:

  1. Make sure that the Search text required property is disabled.
  2. Leave the Block field‑only search property disabled, unless you wish to force users to use a filtering option that works with standard content fields (i.e. filtering options that have _content as their field name).
  3. Enable Search on each page load (ensures that the web part automatically displays results whenever the page is loaded, even without input from a search dialog).
  4. For additional convenience, enable the Filter auto postback property for your Smart search filter web parts (instantly refreshes the search results after users change the filtering options).