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 sources, each representing a specific filter category. For instance, you could have one source for “Articles” and another for “Products,” each searched by its own API widget. When a user selects a filter, your application queries the widget for that category 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 item in your sources 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 your content 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.