Instant aggregation of categories

Facets allow users to filter down their searches, by providing aggregated categories from within their search results. This allows you to create a more dynamic search experience to help your users narrow down on what they're looking for.

You can easily retrieve facets from a search in Relevance AI with the fieldsToAggregate option.

Specify the fields you want to receive facets (or aggregates) for in an array. This may simply be a string containing the field name, or an object where you can also specify the desired resultsSize. Results size specifies the desired amount of top aggregates that should be returned.

Usually, you would want to aggregate fields that are categories. Think fields like: "genre", "brand", "gender", "username".


const fieldsToAggregate = [
    key: "publisher",
    resultsSize: 6

Now you can show users the top genres and publishers in their search results, as well as how many of each are in the results.