Add predictive search to your theme

You can add predictive search to your theme so that suggested results appear immediately as you type into the search field. Predictive search helps customers articulate and refine their search queries, and provides new ways for them to explore an online store. It also lets them quickly browse matches without having to leave their current page to see a separate list of search results.

Example of search dropdown showing recommended products

Predictive search supports suggestions for products, collections, pages, and articles.

Before adding predictive search to your theme, it's important to be familiar with how suggestions are generated, and the UX guidelines.

How suggestions are generated

The predictive search dropdown displays the following information when you enter a query.

Diagram of search dropdown

Legend for the diagram of the search dropdown
Point Description
1Predictive search dropdown
2Product suggestions
3Collection suggestions
4Page suggestions
5Article suggestions

After you start typing into the search bar, predictive search suggests results that are related to what you’re typing. They match search terms either exactly or with typo tolerance on searchable properties of shop resources.

Matching products or variants are returned as product suggestions that drop down from the search bar. For example, you’re looking for a snowboard and type very-fast snowbo. Product suggestions appear for products or variants that contain very, fast, and a term that begins with snowbo.

If a word is separated by a hyphen or space, then it will be considered as two terms. Words or phrases that are separated into multiple terms return different results than a single term that includes the same words. For example, T-shirt and t shirt return the same results, but tshirt does not.

Product variants are returned only when the query matches terms specific to the variant title. Only the variants with the most matching terms are returned as results. For example, a store has a snowboard with a blue variant and a light blue variant. If you search for snowbo, then the snowboard product is returned. However, if you search for light blue snowbo, then only the light blue variant is returned.

Add predictive search to your theme

You can show predictive search results through a section using the following:

The basis of this approach is that your section content builds the general display by looping through each result returned through the resources attribute of the predictive_search object. The predictive_search object isn't defined when the section is initially rendered, so you need to use JavaScript to retrieve the populated section content through the section response of the Predictive Search API.