Kentico CMS 7.0 Developer's Guide

Using the Smart search filter

Using the Smart search filter

Previous topic Next topic Mail us feedback on this topic!  

Using the Smart search filter

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

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. It is designed to be connected to the Smart search dialog or Smart search dialog with results. You can connect more than one filter to these web parts.

 

The behavior of the smart search filter is primarily defined by the properties explained below. You can find descriptions of the web part's other properties in the Kentico CMS Web Parts reference by clicking on the help icon (Help) in the top right corner of the web part properties window.

 

Property Name

Description

Search webpart ID

ID of the Smart search dialog or Smart search dialog with results web part to which the filter should be connected.

Filter mode

Determines what type of user interface element will be used to set the filtering options. Possible choices are a drop-down list, checkboxes, radio buttons or a text box.

Filter auto postback

Indicates whether the search results should automatically be refreshed (via postback) whenever a different filtering option is selected by a user. Not applicable when using the text box Filter mode.

Values

This property is used to specify the options that will be available for selection in the filter. Please see the Defining filtering options section below for details.

Query name

Name of the query which can be used instead of the Values property to dynamically create the filtering options. The query must return the appropriate values depending on the type of the filter.

 

For example, for a standard conditional filter, three columns need to be loaded, which will then be used 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).

 

Examples of how filters work can be found on the sample Corporate Site, specifically on the Examples -> Web parts -> Full-text search -> Smart search -> Smart search filter and Faceted search pages.

 

Defining filtering options

 

The most important part of a Smart search filter web part's configuration is the definition of the options that should be offered to users. In most cases, this will be done 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 used when entering the 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>

 

The logical meaning of each filtering option must also be specified. If the + symbol is added before the option, then only objects whose value in the given field matches the value specified in the second part of the definition will be included in the search. If the - symbol is added, only results that do not match the value will be returned.

 

When entering integer or double type fields as filter options, the type of the value needs to be specified in the following way:

+DocumentCreatedByUserID;(int)53;Administrator

 

Examples:

 

;;All

+classname;cms.smartphone;Smartphones

+_created;[{%CurrentDateTime.AddDays(-7)|(tosearchdatetime)%} TO {%CurrentDateTime|(tosearchdatetime)%}];Past week

+_content;product;Results related to products

 

Search result order filters:

 

When creating filters that change the order of the results (i.e. the Filter is conditional property is disabled), the option definition format described above is also used, but the second part that contains the field value should be left empty. The order will be determined by the values in the specified field.

 

Examples:

 

##SCORE##;;Score

documentcreatedwhen;;Creation date

SKUPrice DESC;;Price descending

 

Text box filter mode:

 

Because text box filters do not offer any selection options, the Values property is instead used to determine which index fields should be searched when a user enters an expression into the text box. Multiple fields can be specified, each one on a new line. Like with standard conditional filters, the + and - symbols determine whether the search should return results that contain the text box value in the given field, or only those that do not.

 

For example, a text box filter could have +DocumentTags in its Value definition. Visitors would then be able to enter the names of document tags into this text box and perform a standard search. The retrieved results would be filtered to contain only those documents that are marked by the specified tags.

 

If you wish to create a text box filter that behaves like a regular search box, use +_content as its only field name.

 

A text box filter may also be used to determine the order of the search results. In this case, the Filter is conditional property must be disabled and the Values property should be left empty. The name of the field used for ordering can then be entered by users into the text box. This scenario is not recommended for use by regular visitors on the live site.

 

 

InfoBox_Exclamation

 

Important!

 

Please note that 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.

 

It is also possible to create filtering options for the fields that are marked as Content by using _content as the field name. Such a condition would be fulfilled if the value is found in any of the content fields.

 

Information about the search field configuration of objects can be found in the Settings for particular object types topic.

 

Filtering without search text (Faceted search)

 

In some cases, you may wish to implement a faceted search based purely on filters. This 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 (Configure) the properties of the web part used to display the search results (Smart search results or Smart search dialog with results) according to the following instructions:

 

1.First, make sure that the Search text required property is disabled.

2.Unless you wish to force users to use a filtering option that works with standard content fields (those that have _content as their field name), also leave the Block field‑only search property disabled.

3.Then enable Search on each page load, which ensures that the results are automatically displayed whenever the page is loaded, even without input from a search dialog.

4.For additional convenience, enable the Filter auto postback property of the used Smart search filter web part(s). Users are then able to instantly refresh the results simply by changing the filtering options.