---
title: Creating custom SQL search providers
related:
  - https://docs.kentico.com/k9/configuring-kentico/setting-up-search-on-your-website/sql-search.md
  - https://docs.kentico.com/k9/custom-development/customizing-providers.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Kentico 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.

> **Note:** This provider only affects the SQL Search engine. The Smart Search engine remains unchanged.
>
> To modify the smart search, [create and use custom search indexes](https://docs.kentico.com/k9/custom-development/miscellaneous-custom-development-tasks/smart-search-api-and-customization/creating-custom-smart-search-indexes.md).

## Adding the custom search provider assembly

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 installation directory (typically _**C:\Program Files\Kentico\\\CodeSamples\CustomSearchProvider**_) to a development folder.
2. Open your web project in Visual Studio (using the **WebSite.sln/WebApp.sln** file).
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 remove all invalid references.
5. Right-click the **CustomSearchProvider** project and select **Add Reference**.
6. Open the **Browse** tab of the **Reference manager** dialog, click **Browse** and navigate to the _**Lib**_ folder of your Kentico web project.
7. Add references to the following libraries:

   - CMS.Search.dll
   - CMS.SearchProviderSQL.dll
8. Right‑click the main Kentico website object (or the CMSApp project if your installation is a web application) and select **Add Reference**.
9. Open the **Solution -> Projects** tab and add a reference to the **CustomSearchProvider** project.
10. **Rebuild** the CustomSearchProvider project.

The CustomSearchProvider project is now integrated into your application.

## Modifying the search provider class

1. Edit the **SearchProvider.cs** class in the **CustomSearchProvider** project.

2. Modify the code of the **Search** method according to the following:

   ```csharp

   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)
   {
       // Limits the search path to only the /Products section of the website
       searchNodePath = "/Products/%";

       // Gets a new instance of the SQL SearchProvider
       CMS.SearchProviderSQL.SearchProvider limitedSearchProvider = new CMS.SearchProviderSQL.SearchProvider();

       // Gets the search result dataset based on the parameters of the Search method and the limited search path

       DataSet searchResults = limitedSearchProvider.Search(siteName, searchNodePath, cultureCode, searchExpression, searchMode, searchChildNodes, classNames, filterResultsByReadPermission, searchOnlyPublished, whereCondition, orderBy, combineWithDefaultCulture);

       return searchResults;
   }

   ```

3. Save the file and **Rebuild** the CustomSearchProvider project.

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.

## Registering the custom search provider

1. Edit your application's web.config file.
2. Add the following key to the configuration/appSettings section:

   ```xml

   <add key="CMSSearchProviderAssembly" value="CMS.CustomSearchProvider" />

   ```

The system loads the **SearchProvider** class from the namespace specified as the value of the **CMSSearchProviderAssembly** key.

## Result

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.

The search now only returns results from the /Products section of the website.

> **Tip:** This customization example is purely demonstrative. If you need to change the search path, directly set the Path property of individual SQL search web parts or controls.
