BigCommerce’s GraphQL Storefront API lets merchants on headless storefronts use faceted and textual search powered by results from our back-end search engine. These built-in capabilities also allow Stencil developers to take advantage of our search engine.
Faceted search is a method of helping shoppers navigate a store’s product inventory by categorizing products into various categories, brands, product features, and more.
Textual search is a method of retrieving products based on product fields, for example, product name and description.
The GraphQL Storefront API’s faceted and textual search lets you create the following features:
Note
You can query facets, filter by rating, or filter by “in-stock” only if the merchant is on a Pro or Enterprise plan. A merchant must enable product filtering for facets to be returned.
In addition, only facets that a merchant marks as visible in their Product Filtering settings will be returned.
To use faceted and textual search, specify a filter in the argument for SearchProducts. For faceted search, you can filter by price, rating, among other features and attributes of products. For textual search, use the searchTerm field.
The filters below affect both the products and facets that are returned. For example, filtering by rating returns only products within the specified rating range and only facets that have products within the rating range.
To get products, specify products as a field in searchProducts.
Below is an example request that returns the first two products with a rating between three and five:
You can sort the products that are returned using the sort field. The sort affects only the list of products returned. The product filtering settings determine how facets are sorted.
Below is an example query that searches for products using a search term and sorts the returned products in alphabetical order:
For a list of product fields that searchTerm searches, see the Store Search Product Fields article.
To get facets, specify filters as a field in searchProducts.
Below is an example request that returns the specified facets that have products with a rating between three and five:
For a complete list of facets, see the GraphQL Storefront Playground.
To get both products and facets, specify both products and filters fields in searchProducts.
If product filtering has not been enabled, you will receive an empty array for the returned facets, though products will still be returned. To enable product filtering, refer to the KB Article below: