---
title: Creating custom smart search analyzers
related:
  - https://docs.kentico.com/k9/configuring-kentico/setting-up-search-on-your-website/creating-search-indexes.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).

If the selection of built‑in indexing analyzers is insufficient, you can specify custom‑written or third‑party analyzers for search indexes. Custom analyzers allow you to perform text tokenization according to any requirements. You can use custom analyzers with any type of smart search index.

To use a custom analyzer, you need to create and add the appropriate code files to your web project. Classes defining custom analyzers must:

- inherit from the **Lucene.Net.Analysis.Analyzer** class
- implement the **CMS.Search.ISearchAnalyzer** interface

## Example

The following example demonstrates how to assign a custom analyzer to a smart search index. The sample analyzer divides text into tokens at non-letter characters and is case insensitive.

### Adding the custom analyzer project

1. Copy the **CustomSearchAnalyzer** project from your Kentico installation directory (by default _C:\Program Files\Kentico\\\CodeSamples\CustomSearchAnalyzer_) to a development folder.
2. Open your Kentico web project using the **WebSite.sln** file (**WebApp.sln** if you installed the project as a web application).
3. Click **File -> Add -> Existing Project** and select the **CustomSearchAnalyzer.csproj** file in the folder where you copied the **CustomSearchAnalyzer** project.
4. Right‑click the Kentico website in the Solution explorer (or the **CMSApp** project if your installation is a web application) and choose **Add Reference**.
5. Switch to the **Solution -> Projects** tab, select the **CustomSearchAnalyzer** project and click **OK** to add the project reference.
6. Unfold the **References** section of the **CustomSearchAnalyzer** project and delete all invalid references.
7. Right-click the **CustomSearchAnalyzer** project and select **Add Reference**.
8. Open the **Browse** tab of the **Reference Manager** dialog, click **Browse,**  and navigate to the **Lib** folder of your Kentico web project on the disk.
9. Add a reference to the following libraries:

   - **CMS.Search.dll**
   - **Lucene.Net.v3.dll**
10. Rebuild the **CustomSearchAnalyzer** project (Build the entire solution on web application projects).

### Assigning the custom analyzer to a search index

1. Log in to the Kentico administration interface and open the **Smart search** application.
2. Click **New Index**. Fill in the following properties:

   - **Display name**: Space analyzer page index
   - **Index type**: Pages
   - **Analyzer type**: Custom
   - **Analyzer class - Assembly name**: CMS.CustomSearchAnalyzer
   - **Analyzer class - Class**: CMS.CustomSearchAnalyzer.CustomSearchAnalyzer
3. Click **Save**.
4. Switch to the **Indexed content** tab and click **Add allowed content**.
5. Type _/%_ into the **Path** field to index all pages and click **Save**.
6. Switch over to the **Cultures** tab and add the cultures used by your website.
7. Go to the **General** tab and **Rebuild** the index.

You can test the index and its analyzer by switching to the **Search preview** tab and searching for words from the content of the website's pages.

> **Info:** **Defining custom analyzers in App\_Code**
>
> If you do not wish to add a new project to the application, you may alternatively create the required classes under the **App\_Code** folder, and register the custom analyzer class using the same approach described in [Creating custom smart search indexes](https://docs.kentico.com/k9/custom-development/miscellaneous-custom-development-tasks/smart-search-api-and-customization/creating-custom-smart-search-indexes.md).
>
> In this case, you need to change the **Assembly name** and **Class** of the index's analyzer accordingly.
