Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Navigation [hide] [expand]
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Episerver Commerce includes an extensive, system-wide search engine. You can make any information available to the search engine, even if that information is not in the Episerver Commerce database. Some systems, such as Catalog and Orders, have additional search features. 

Episerver Commerce has its own pluggable API for search providers. The search engine is based on the ASP.NET provider model, meaning you can write your own providers to search servers. Episerver Commerce comes with providers for Lucene and SOLR. You can integrate Episerver Commerce with Episerver Find to create more advanced search-based navigation and filtering for websites.

Classes in this topic are available in the following namespaces:

Architecture

Episerver Commerce has a layer built on top of Lucene for easy integration. A MediachaseSearch layer provides a base layer to simplify the interface. This base creates an index for any data source, while you still have access to the Lucene classes. Searchable data is written to a file index.

Search Architecture

SearchExtensions provide catalog indexing and a searching implementation using the MediachaseSearch layer, which is built into Commerce Manager and includes several controls making use of this implementation. You can create you own search implementation on top of MediachaseSearch.

Indexing

To make data available, you must first index it by calling the Mediachase.Search.SearchManager.BuildIndex(bool rebuild) method. Click the Build or Rebuild buttons in Commerce Manager to call the method, or call it through the Quartz service that calls BuildIndex method on the predefined schedule.

The individual indexer implementations are defined in the mediachase.search.config file. The default catalog indexer included, Mediachase.Search.Extensions.Indexers.CatalogIndexBuilder, Mediachase.Search.Extensions, reads the catalog data and calls the SearchProvider.Index(string applicationName, string scope, ISearchDocument document) method.

Implement the method by the provider that is currently configured. The provider is passed an ISearchDocument, containing properties that need to be indexed. You can replace the indexer completely or extend the existing indexer by inheriting CatalogIndexBuilder class and overriding OnCatalogEntryIndex method. You also can add new indexers.

By default, the indexer only populates fields that are marked searchable in the meta-configuration and some system fields like price, name, and code. Depending on the provider, additional configuration changes need to be made for those fields to make it to the index.

Calling BuildIndex with rebuild = false only adds indexes that have changed since the last index was created. The system keeps track of when the last index was performed using the .build file. Location of the .build file is configured inside Mediachase.Search.config file for each indexer defined.

Example: build index command

SearchManager searchManager = new SearchManager(applicationName);
searchManager.BuildIndex(false);

Catalog metadata fields have options that allow you to specify:

  • Whether a field is added to the index. This alone does not make the field searchable.
  • Whether the field value is stored or not. Stored = stored in an uncompressed format. Not stored = putting the value into the index in a compressed format. You store a value only if you will use the value as part of the displayed text in the results to the user.
  • Whether the field is tokenized. A field must be tokenized to be searchable. When a field is tokenized, the text is broken down into individual searchable words, and common words are omitted.

Searching

When the data is indexed, this index is searched. Search is done by calling the ISearchResults Mediachase.Search.Search(ISearchCriteria criteria) method. The method call is handled by the configured search provider and returns the ISearchResults interface.

Example: simple catalog search

CatalogEntrySearchCriteria criteria = new CatalogEntrySearchCriteria();
criteria.SearchPhrase = "canon";
SearchManager manager = new SearchManager(AppContext.Current.ApplicationName);
SearchResults results = manager.Search(criteria);

The search phrase can contain complex search syntax that is specific to a provider used.

Facets and filters

Another capability extending the Lucene.NET functionality is the ability to create Facets, which are a type of filtering that can further narrow a search. In the configuration file, facets such as SimpleValue, PriceRangeValue, and RangeValue types can be found.

Facets are organized into facet groups. A facet group is referred to as a Filter in the configuration file. For instance, a Color facet group can have a Red facet. In the configuration, Color would be the filter and Red would be a SimpleValue. A facet group is linked to a particular field or meta-field. You can specify facets as part of the ISearchCriteria interface.

The front end includes controls that read a special configuration file to automatically populate the facet property of the ISearchCriteria interface. These filters are stored in Mediachase.Search.Filters.config. To add a new filter, add a new field to the index and add a record to the configuration file. The filter appears as soon as the data is available.

Related topics

Last updated: Oct 12, 2015