Facets
Facets are a powerful tool for filtering and narrowing down search results on the Orama search engine.
With the Orama Faceted Search API, users can filter their search results by various criteria, such as category, price range, or other attributes, making it easier to find the information they need. Whether you’re building a website, mobile app, or any other application, the Orama Faceted Search API is the perfect solution for adding faceted search functionality to your project.
Given the following Orama schema:
Orama will be able to generate facets at search-time based on the schema.
To do so, we need to specify the facets
property in the search
configuration:
This will generate the following result:
As you may have noticed, the facets
property is an object
that contains different
configurations depending on the property type specified in the schema.
String facets
If a property is specified as string
in the schema, the facet will accept the following
configuration:
Property | Type | Default | Description |
---|---|---|---|
order | string | DESC | Order of the values. Can be either ASC or DESC . |
limit | number | 10 | Maximum number of values to return. |
offset | number | 0 | Number of values to skip. |
In the search result, string
facets will be returned as an object
with the following properties:
Number facets
If a property is specified as number
in the schema, the facet will accept the following
configuration:
Property | Type | Default | Description |
---|---|---|---|
ranges | array | [] | Array of ranges to consider. |
Each range is an object
with the following properties:
Property | Type | Description |
---|---|---|
from | number | Minimum value of the range. |
to | number | Maximum value of the range. |
In the search result, number
facets will be returned as an object
with the following properties:
Please note that the from
and to
values are inclusive. Note also that the order of the ranges
is guaranteed as specified in the configuration.
Boolean facets
If a property is specified as boolean
in the schema, the facet will accept the following
configuration:
Property | Type | Default | Description |
---|---|---|---|
true | boolean | true | Whether to consider true values. |
false | boolean | true | Whether to consider false values. |
In the search result, boolean
facets will be returned as an object
with the following properties:
Enum facets
If a property is specified as enum
in the schema, no configuration is required.
In the search result, enum
facets will be returned as an object
with the following properties:
How facets works on array fields
Orama treats each array element as a single element of the facet:
result.facets
is the following object: