Create a custom search service

Sitefinity CMS supports the following search services out of the box: Lucene.NET (default service), Azure Cognitive Search service, and Elasticsearch service. If support for another search service is needed (such as Solr, SharePoint Search, etc.), you can accomplish this with custom code. The ISearchService interface must be implemented and then to replace the default service, the interface should be registered by invoking ObjectFactory.RegisterType.

Sitefinity CMS calls the UpdateIndex method of the your implementation when you create and modify each item. It provides a collection of IDocument instances to be added or updated in the index.

The Search method of the registered interface (either the built-in or a custom implementation) is invoked whenever the user uses the Search widget. If the Search widget is not used on your Sitefinity CMS site, the other interface methods can be used in order to run a search query directly through the API.

The Search method takes ISearchQuery and SearchOptions as arguments. SearchOptions are specifically used for defining the search type, scoring settings when search scoring is required (only available for Azure Cognitive Search service) or if search facets are required (available for Azure Cognitive Search and Elasticsearch services). In the default implementation, the query is instantiated and its ISearchGroup groups are built with the BuildQuery method of the IQueryBuilder interface. You can add or remove groups to the query once it is built.
ISearchGroup consists of ISearchTerm and ISearchGroup enumerations. When building the search expression, the group operator is used between the terms and the groups.
ISearchTerm describes a search term with its Field and Value. In most cases, terms contains the search field names and the text that the user is searching for.
ISearchFilter defines a search filter for the search query. The filter normally contains static clauses like language filtering, type filtering, date filtering, or any other custom filtering.

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?