Retrieve and Apply Facets
Facets are attribute categories for records that customers can use to further filter results. For example, if a customer searches for shirts, the available facets might include size, color, or material type. Refer to the Facets section of Search Results Customizations as well as Manage Facets for Category Pages in the Monetate Knowledge Base for more information.
If a customer initiates a search on your site without typing anything into the search bar, then Personalized Search still returns results based on the settings you've configured for Personalized Site Search or Personalized Category Pages, as applicable, in the Monetate platform. Additionally, Personalized Search displays all the indexed facets from the mapped product catalog, excluding any that you've removed using the settings you've configured in the Monetate platform.
Within a Personalized Search API request, you can both retrieve applicable facets to display to customers and apply facets to filter results.
Retrieving facets is a computationally expensive operation. For best performance, you should minimize the number of times you retrieve them. For example, if you're paginating search results, retrieve facets only on the first query.
To retrieve facets in a Personalized Search API request, add the filtersToReturn object with its enabled parameter set to true.
You must contact your dedicated Customer Success Manager (CSM) if you want to use a rating filter ("key": "rating") in the request.
The facets appear on your site as filters that the customer can apply to further narrow the search results.
The following example is a request with more optional parameters in the filtersToReturn object, along with the response:
Applying facets to a query filters the results based on the selected facets and values. Run this query after a customer selects the facets they want to filter by. Apply facets in a query by using the applyFilters object.
If the customer selects only one value of only one facet, then Personalized Search ensures that all the returned records contain the facet attribute with the customer-selected value. However, if the customer selects multiple values for one facet, then the Boolean parameter singleSelect of the applyFilters object determines how Personalized Search applies them:
- When singleSelect is true, then a record must contain all the selected values to be included in the response.
- When singleSelect is false, then a record needs only to contain one of the selected values to be included in the response.
If constraints are added for multiple facets and singleSelect is false, then a record must have at least one value from each of the filter conditions provided.