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.
How it works
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
The search provider system supports various UI components, including the search features in Commerce Manager and the Catalog UI. It can also be used to build user-facing features in the site implementation. An even more powerful approach is to integrate Episerver Commerce with Episerver Search & Navigation to create more advanced search-based navigation and filtering for websites.
Classes in this topic are available in the following namespaces:
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.
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.
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.
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 marked searchable in the metafield configuration
- fields decorated with the [Searchable] attribute on catalog content models
- some system fields like price, name, and code.
Depending on the provider, additional configuration changes need to be made to index those fields.
Calling BuildIndex with rebuild = false only adds indexes that changed since the last index was created. The system tracks 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);
- Whether a field is added to the index. This alone does not make the field searchable.
- Whether a field value is stored. Stored = stored in an uncompressed format. Not stored = add the value to the index in a compressed format. Only store a value if you will use it as part of search result text.
- Whether a field is tokenized, that is, broken into individual, searchable words, and common words are omitted. Only tokenized fields are searchable.
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.
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.
Facets and filters
Another capability extending the Lucene.NET functionality is the ability to create facets, a type of filtering that can further narrow a search. The configuration file contains facets like SimpleValue, PriceRangeValue, and RangeValue.
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 is the filter and Red is 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.