Include facet alias in API data

Created on 7 October 2024, about 2 months ago

I have a use case where it would be helpful to have the facet alias included along with the facet key in the data structure provided by the API for each facet. The alias is useful because it is the configurable string to appear for the query parameter representing that facet.

In the current implementation -- at least in my use case -- I need to make sure the facet alias is the same as the key (machine name) because I don't have access to the value of the alias when interacting with the API. Providing the alias in the API data would allow the key and the alias to be different.

I've done a very quick test and I think there is only one change needed to add the facet alias. In search_api_decoupled/modules/facets/src/EventSubscriber/SearchApiEndpointEventSubscriber.php, the class SearchApiEndpointEventSubscriber has a public function onSearchResultsAlter where it appears facets are added to the search api endpoint response. In the loop that processes each facet, I think adding the following to the $search_response['facets'][] array will do the trick:

'alias' => $facet->getUrlAlias(),

getUrlAlias() being a function defined for the facet entity.

It's possible I missed something really obvious, but I tested this change and it did provide the alias in the endpoint response.

✨ Feature request
Status

Active

Version

1.0

Component

Facets

Created by

πŸ‡ΊπŸ‡ΈUnited States aaronpinero

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024