Filtering is a critical feature that enhances the user experience by helping users quickly narrow down search results to what’s most relevant to them. While the API does not have a built-in filtering feature, there are two primary strategies you can employ to achieve this functionality:
This guide explains these approaches, outlines their pros and cons, and helps you choose the best method for your use case.
This approach involves creating distinct indexes, each representing a specific filter category. For instance, you could have one index for “Articles” and another for “Products.” When a user selects a filter, your application queries the corresponding index to retrieve the results.
This method is suitable for simple, static filtering needs where categories are mutually exclusive and the filtering logic is straightforward.
In this approach, each indexed item is enriched with metadata fields such as type, tags, or categories. These fields allow you to define multiple properties for an item, enabling dynamic and flexible filtering directly on the client side.
type
tags
categories
To learn how to enrich indexed items with metadata, refer to the Search Results Customization Guide.
This method is ideal for complex or dynamic filtering needs, such as when items need to belong to multiple categories or when filters need to be combined in various ways.
The choice between the two approaches depends on your specific requirements:
For most use cases, metadata selectors provide the flexibility needed to create a richer, more user-friendly filtering experience.