Try our conversational search powered by Generative AI!

Loading...
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

This document describes how to extend your EPiServer Commerce solution by creating your own search provider. the examples here are based on Lucene and SOLR. Refer also to Customizing Search for related information.

Classes referred to here are available in the following namespaces:

Implementing a search provider

To implement a new search provider or to extend or replace an existing one, you will need to create a new class that implements the SearchProvider abstract class. That class contains one method that performs the search, while the rest deals with indexing the data. It is typically much easier to take one of the existing implementations (SOLR or Lucene) as a starting point.

Example: implementing the SearchProvider class

C#
public abstract class SearchProvider : ProviderBase
    {
        /// <summary>
        /// Gets the class type of the query builder. This class will be used to dynamically convert SearchCriteria to the query
        /// that Search Provider can understand.
        /// </summary>
        /// <example>
        /// // the following type will build query for the SOLR server
        /// "Mediachase.Search.Providers.Solr.SolrSearchQueryBuilder, Mediachase.Search.SolrSearchProvider"
        /// </example>
        /// <value>The type of the query builder.</value>
        public abstract string QueryBuilderType { get; }

        /// <summary>
        /// Searches the datasource using the specified criteria. Criteria is parsed by the query builder specified by <typeparamref name="QueryBuilderType"/>.
        /// </summary>
        /// <param name="applicationName">Name of the application.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public abstract ISearchResults Search(string applicationName, ISearchCriteria criteria);

        /// <summary>
        /// Adds the document to the index. Depending on the provider, the document will be commited only after commit is called.
        /// </summary>
        /// <param name="applicationName">Name of the application.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="document">The document.</param>
        public abstract void Index(string applicationName, string scope, ISearchDocument document);

         /// <summary>
         /// Removes the document by specifying scope (core in SOLR), key (a field that can be used to lookup for a document) and
         /// value of the key.
         /// </summary>
         /// <param name="applicationName">Name of the application.</param>
         /// <param name="scope">The scope.</param>
         /// <param name="key">The key.</param>
         /// <param name="value">The value.</param>
         /// <returns></returns>
         public abstract int Remove(string applicationName, string scope, string key, string value);

         /// <summary>
         /// Removes all documents in the specified scope.
         /// </summary>
         /// <param name="applicationName">Name of the application.</param>
         /// <param name="scope">The scope.</param>
         public abstract void RemoveAll(string applicationName, string scope);

         /// <summary>
         /// Closes the specified provider.
         /// </summary>
         /// <param name="applicationName">Name of the application.</param>
         /// <param name="scope">The scope.</param>
         public abstract void Close(string applicationName, string scope);

         /// <summary>
         /// Commits changes made to this instance.
         /// </summary>
         /// <param name="applicationName">Name of the application.</param>
         public abstract void Commit(string applicationName);
    }

The main classes in this SOLR implementation example are:

  • SolrSearchProvider - the main class.
  • SolrSearchQueryBuilder - converts ISearchCriteria to the provider native language and is called within the Search method of the provider.

See also

  • The Search section in the EPiServer CMS SDK
Do you find this information helpful? Please log in to provide feedback.

Last updated: Mar 31, 2014

Recommended reading