Kentico CMS allows you to write your own SQL search provider, which you can use to integrate a third-party search engine. You can also create a custom search provider if you need to modify or filter search results returned by the standard search engine.
You cannot customize the search provider in the App_Code folder. The modifications must be added as part of a new assembly, which you then need to register via the CMSSearchProviderAssembly web.config key.
This provider only affects the SQL Search engine. The Smart Search engine remains unchanged.
To modify the smart search, create and use a custom search index as described in Modules -> Smart Search -> Managing indexes -> Defining custom index content.
The following example demonstrates how to customize the SQL search provider so that it only searches a limited section of the website.
1. Copy the CustomSearchProvider project from your Kentico CMS installation directory (typically C:\Program Files\KenticoCMS\<version>\CodeSamples\CustomSearchProvider) to a development folder.
2. Open your CMS web project in Visual Studio through the WebProject.sln file (or WebApp.sln if you are using a web application installation).
3. Click File -> Add -> Existing Project and select CustomSearchProvider.csproj in the folder where you copied the CustomSearchProvider project.
4. Unfold the References section of the CustomSearchProvider project and delete all invalid references.
5. Right-click the CustomSearchProvider project and select Add Reference.
6. Open the Browse tab of the Add Reference dialog and navigate to the bin folder of your CMS web project on the disk.
7. Add references to the following libraries:
8. Right‑click the CMS website object (or the CMSApp project if your installation is a web application) and select Add Reference.
9. Open the Projects tab and add a reference to the CustomSearchProvider project.
The CustomSearchProvider project is now integrated into your application.
1. Edit the SearchProvider.cs class in the CustomSearchProvider project.
2. Modify the code of the Search method according to the following:
public DataSet Search(string siteName, string searchNodePath, string cultureCode, string searchExpression, SearchModeEnum searchMode, bool searchChildNodes, string classNames, bool filterResultsByReadPermission, bool searchOnlyPublished, string whereCondition, string orderBy, bool combineWithDefaultCulture)
In real customization scenarios, you can modify the Search method to behave according to any requirements. The method must always return a DataSet containing the search results.
3. Save the file and Build the CustomSearchProvider project.
1. Edit your application's web.config file.
2. Add the following key to the configuration/appSettings section:
<add key="CMSSearchProviderAssembly" value="CMS.CustomSearchProvider" />
The system loads the SearchProvider class from the namespace specified as the value of the CMSSearchProviderAssembly key.
To try out the customized search engine, open the live website and search for text using the SQL Search engine. For example, you can use the Examples -> Web Parts -> Full‑Text Search -> SQL Search -> SQL Search dialog with results page on the sample Corporate site website.
The search now only returns results from the /Products section of the website.
This customization example is purely demonstrational. If you need to change the search path, directly set the Path property of individual SQL search web parts or controls.