Table of Contents
This document provides a basic introduction to searching and filtering in EPiServer CMS. A search solution to help website visitors find what they want can be created by combining EPiServer Data Source controls, listing controls and even third-party controls (.NET etc). If you require more extensive search functionality in your website solution there are also third-party search engines that can be integrated with EPiServer.
The EPiServer CMS SearchDataSource is one of the major data source controls shipped with EPiServer CMS it is a flexible web control enabling different types of searches in an EPiServer CMS website, see below for further information.
Searching for a Page
The SearchDataSource web control can support text and property searches, also different criteria can be applied to both types of searches.
Searching for pages often comes in the following distinct forms:
- Text-based search (keywords) usually allow the user to input one or more keywords; any pages that contain those words should be returned and presented to the user.
- Property-based search provides an efficient and powerful tool to retrieve pages
based on any property values, typically of types other than string. From markup
(or the visual design mode in Visual Studio), the EPiServer SearchDataSource web control can support both types of searches;
also different criteria can be applied to both types of searches. From
code-behind files, you can also call the FindPagesWithCriteria()
method of the EPiServer.DataFactory class to perform property-based searches.
The FindPagesWithCriteria method is used by the SearchDataSource control when
performing a property-based search.
From markup add PropertyCriteria controls to the SearchDataSource tag. From code-behind files, create EPiServer.PropertyCriteria instances and insert them into a PropertyCriteriaCollection that is passed to the FindPagesWithCriteria method. You are required to add the SearchDataSource control's DataSourceID attribute to the control that renders the data.
In order to search for file content and file information the SearchFiles attribute must be set to true in the SearchDataControl.
Sorting and Filtering
A filter is a general mechanism in EPiServer that is used to manage and manipulate information in listings and collections of pages (PageDataCollection). As a developer, you can construct your own filters, which can then be used in conjunction with listings to display content. A filter has three primary functions and is used for adding, removing and sorting.
See the following most common built-in filter options:
- SortBy and SortDirection used to specify a custom property to sort on
- SortOrder uses a predefined sorting from FilterSortOrder enum
- MaxCount and SkipCount to limit number of items
- EnableVisibleInMenu, PageTypeID, etc
- LanguageBranches collection to limit the search
- Criteria collection constrains the search result (used for property-search or as filters)
- SelectParameters collection to set attribute values from other sources (Control,Cookie, Form, Profile, QueryString, Session, EPiServer Property)
The EPiServer filter classes and enumerations are documented in EPiServer.Filters namespace.
It is also possible to create your own filters by extending the EPiServer.Filters.IPageFilter class.