Introduction
The Facets module allows site builders to easily create and manage faceted search interfaces.
Features
If you are the developer of a search API backend implementation and want to support facets with your service class, too, you'll have to support the "search_api_facets" feature. In short, when executing a query, you'll have to return facet terms and counts according to the query's "search_api_facets" option. For the module to be able to tell that your server supports facets, you will also have to change your service's supportsFeature() method to something like the following:
public function getSupportedFeatures() {
return ['search_api_facets'];
}
If you don't do that, there's no way for the facet source to pick up facets.
The `search_api_facets`` option looks as follows:
$query->setOption('search_api_facets', [
$facet_id => [
// The Search API field ID of the field to facet on.
'field' => (string),
// The maximum number of filters to retrieve for the facet.
'limit' => (int),
// The facet operator: "and" or "or".
'operator' => (string),
// The minimum count a filter/value must have been returned.
'min_count' => (int),
// Whether to retrieve a facet for "missing" values.
'missing' => (bool),
],
// …
]);
The structure of the returned facets array should look like this:
$results->setExtraData('search_api_facets', [
$facet_id => [
[
'count' => (int),
'filter' => (string),
],
// …
],
// …
]);
A filter is a string with one of the following forms:
- "VALUE"
: Filter by the literal value VALUE (always include the quotes, not
only for strings).
- [VALUE1 VALUE2]
: Filter for a value between VALUE1 and VALUE2. Use
parentheses for excluding the border values and square brackets for including
them. An asterisk () can be used as a wildcard. E.g., ( 0) or [* 0) would be
a filter for all negative values.
- !
: Filter for items without a value for this field (i.e., the "missing"
facet).