How to Implement Autocorrect with Facet Selection in Elevate¶
Overview¶
When a visitor performs a search containing a misspelling, Elevate's autocorrection feature may return results for the corrected term. The autocorrection feature is exposed via the search page endpoint/method. However, if the visitor then applies a facet filter, the autocorrection is no longer applied automatically. To ensure consistent and relevant results, the q
parameter in subsequent requests must use the corrected phrase returned from the initial search.
Problem Description¶
- Scenario: User searches with a typo → Elevate autocorrects and returns relevant results → User selects a facet filter.
- Issue: If the next request still uses the misspelled term in the q parameter, autocorrection will not be applied and may yield to no hits, or yield hits based on the misspelled results which may confuse the site visitors.
- Solution: Use the corrected phrase from the initial search response in all follow-up queries with facets.
Step-by-Step Implementation¶
Step 1. Initial Search Request with Misspelling.¶
The visitor searches with a misspelled term for example “jakcet”, and the following query is sent to Elevate: /storefront/v3/queries/search-page?customerKey=TEST&sessionKey=TEST&touchpoint=DESKTOP&locale=sv-SE&market=SE&q=jakcet
Step 2. Capture the Corrected Phrase.¶
The response will include: - Search results based on the autocorrected term. - The corrected phrase itself (e.g., "jacket"), below is a snippet of Elevate’s response:
{
"q": "jakcet",
"autoCorrect": {
"q": "jacket",
"originalTotalHits": 0
}
}
Step 3. Send Corrected Phrase When Applying Facets.¶
When the visitor applies a facet (e.g., color=BLUE), send the corrected phrase in the q parameter instead of the original misspelling: /storefront/v3/queries/search-page?customerKey=TEST&sessionKey=TEST&touchpoint=DESKTOP&locale=sv-SE&market=SE&q=jacket&f.color=BLUE
Summary¶
To maintain search accuracy after a misspelled query followed by a facet selection:
- Accept the misspelled input in the first request.
- Present a visual cue that the phrase has been autocorrected, such as a text that says “Your search for jakcet did not match any products, corrected to jacket” and present the search results based on the autocorrected phrase. If the original phrase has
originTotalHits > 0
, you can provide a link to the original misspelled phrase, and use the parameterorigin=UNDO_AUTO_CORRECT
. - If a visitor selects a facet, use the corrected phrase in all follow-up requests with facets.