You can add more complex search completion support to your application via the Salesforce B2C Commerce APIs. Before you begin coding, review the SiteGenesis application to see how this feature was implemented.
Review these SiteGensis files to understand how this feature was implemented, for example:
- SiteGenesis Storefront Core/cartridge
- Data files:
When you implement this feature, you need to consider the performance impact. The SiteGenesis implementation shows suggestions as a popup immediately after the customer starts entering text in the search field. The popup's HTML content is fetched using an asynchronous AJAX call. The SiteGenesis application executes the AJAX calls in a gracefully way as follows:
- Only one request at a time
- Only if search phrase has changed
- If the search phrase has changed multiple times while a single AJAX call was running, only the last most recent search phrase is used in the next AJAX call (no queuing)
- The page cache must be used on the server
- The minimum input length is set to three (3) characters
Use the B2C Commerce APIs to customize your code. The Suggest API consists of the following:
dw.suggest.SuggestModelclass: main access point to obtain suggestions
dw.suggest.Suggestionsclass: container for bundling suggested items (for example, products), suggested phrases, and the specific terms of a particular type (for example, auto completed products names), for example, dw.suggest.ProductSuggestions
dw.suggest.SuggestedTermsclass: lists of terms suggested for a single term of the customer input
dw.suggest.SuggestedTermclass: provided by specific classes such as SuggestedProduct or SuggestedContent. Each SuggestedTerm object represents a single suggested term and its associated attributes and flags
dw.suggest.SuggestedPhrasesclass: represents one or more search phrases suggested by B2C Commerce
dw.catalog.ProductSearchModel.getSuggestedSearchPhrasemethod: provides the corrected search phrase as a hint on the search results page.
See the B2C Commerce APIs for more information.
Matches are defined as follows:
|Match Type||Ranking Priority||Description|
|Exact||1||The original and suggested terms are exactly equal|
|Auto completion||2||The original is a prefix of the suggested term.|
|Fuzzy||3||The original and suggested terms differ by a few characters, similar to spell correction|
The match types and ranking described here is only applicable for suggested terms, that is, auto completion and auto correction. It does not affect any search results or sorting rules.