You are here

private function SearchApiAlgoliaBackend::extractFacetsData in Search API Algolia 8

Same name and namespace in other branches
  1. 3.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::extractFacetsData()
  2. 2.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::extractFacetsData()

Extract facets data from response.

Parameters

array $facets: Facets to extract.

array $data: Facets data from response.

Return value

array Facets data in format required by Drupal.

1 call to SearchApiAlgoliaBackend::extractFacetsData()
SearchApiAlgoliaBackend::search in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
Executes a search on this server.

File

src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php, line 644

Class

SearchApiAlgoliaBackend
Class SearchApiAlgoliaBackend.

Namespace

Drupal\search_api_algolia\Plugin\search_api\backend

Code

private function extractFacetsData(array $facets, array $data) {
  $facets_data = [];
  foreach ($data as $field => $facet_data) {
    if (!in_array($field, $facets)) {
      continue;
    }
    foreach ($facet_data as $value => $count) {
      $facets_data[$field][] = [
        'count' => $count,
        'filter' => '"' . $value . '"',
      ];
    }
  }
  return $facets_data;
}