Search Suggestion

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/cartridge
    • static/default/js/app.js
    • templates/default/resources/appresources.isml
  • SiteGenesis Storefront Core/cartridge
    • pipelines/Search.xml
    • static/default/css/style.css
    • templates/default/search/suggestionsbeta.isml
    • templates/resources/
  • Data files: sg20_demo_data_no_hires_images/meta/system-objecttype-extensions.xml

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.SuggestModel class: main access point to obtain suggestions
  • dw.suggest.Suggestions class: 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.SuggestedTerms class: lists of terms suggested for a single term of the customer input
  • dw.suggest.SuggestedTerm class: 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.SuggestedPhrases class: represents one or more search phrases suggested by B2C Commerce
  • dw.catalog.ProductSearchModel.getSuggestedSearchPhrase method: provides the corrected search phrase as a hint on the search results page.

See the B2C Commerce APIs for more information.

Match Types

Matches are defined as follows:

Match TypeRanking PriorityDescription
Exact1The original and suggested terms are exactly equal
Auto completion2The original is a prefix of the suggested term.
Fuzzy3The 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.