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
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
- Open your Kentico solution in Visual Studio.
- Add a new Class Library project to the Kentico solution, for example named CustomSearchAnalyzer.
- Add references to the required Kentico libraries (DLLs) for the new project:
- Right-click the project and select Add -> Reference.
- Select the Browse tab of the Reference manager dialog, click Browse and navigate to the Lib folder of your Kentico web project.
Add references to the following libraries:
- Reference the CustomSearchAnalyzer project from the Kentico web project (CMSApp or CMS).
- Open your Kentico program files directory (by default C:\Program Files\Kentico\<version>) and expand the CodeSamples\CustomizationSamples\CustomSearchAnalyzer subfolder.
- Copy the following files into the CustomSearchAnalyzer directory in your web project:
- Include the new files into the CustomSearchAnalyzer project in Visual Studio:
- Expand the CustomSearchAnalyzer project in the Solution Explorer.
- Click Show all files at the top of the Solution Explorer.
- Select the new files while holding the Ctrl key.
- Right-click one of the files and select Include in Project.
- Build the CustomSearchAnalyzer project (Build the entire solution on web application projects).
Assigning the custom analyzer to a search index
- Sign in to the Kentico administration interface and open the Smart search application.
- Open the Local indexes tab.
- Click New Index. Fill in the following properties:
- Display name: Space analyzer page index
- Index type: Pages
- Analyzer type: Custom
- Analyzer class - Assembly name: CustomSearchAnalyzer
- Analyzer class - Class: CMS.CustomSearchAnalyzer.CustomSearchAnalyzer
- Click Save.
- Switch to the Indexed content tab and click Add allowed content.
- Type /% into the Path field to index all pages and click Save.
- Switch over to the Cultures tab and add the cultures used by your website.
- 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.
Was this page helpful?