Create your own search provider
Describes how to extend your Optimizely Commerce Connect solution by creating your own search provider. The examples in this topic are based on Lucene.
Classes in this topic are available in the following namespaces:
Mediachase.SearchMediachase.Search.ExtensionsMediachase.Search.Extensions.Indexers
See also Customize search.
To implement a search provider or extend or replace an existing one, create a class that implements the SearchProvider abstract class. That class contains one method that performs the search; the others handle indexing the data. Use the existing Lucene implementation as a starting point.
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 the Search Provider can understand.
/// </summary>
/// <example>
/// // The following type will build queries for the SOLR server:
/// "Mediachase.Search.Providers.Solr.SolrSearchQueryBuilder, Mediachase.Search.SolrSearchProvider"
/// </example>
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>
public abstract ISearchResults Search(string applicationName, ISearchCriteria criteria);
/// <summary>
/// Adds the document to the index. Depending on the provider, the document will be
/// committed only after <see cref="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 used to
/// look up a document), and the 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>
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 Lucene implementation example are:
LuceneSearchProvider– The main class.LuceneSearchQueryBuilder– ConvertsISearchCriteriato the provider's native language and is called within theSearchmethod of the provider.
Updated 20 days ago
