You are here

function hook_search_api_algolia_objects_alter in Search API Algolia 8

Same name and namespace in other branches
  1. 3.0.x search_api_algolia.api.php \hook_search_api_algolia_objects_alter()
  2. 2.0.x search_api_algolia.api.php \hook_search_api_algolia_objects_alter()

Alter Algolia objects before they are sent to Algolia for indexing.

Parameters

array $objects: An array of objects ready to be indexed, generated from $items array.

\Drupal\search_api\IndexInterface $index: The search index for which items are being indexed.

\Drupal\search_api\Item\ItemInterface[] $items: An array of items to be indexed, keyed by their item IDs.

1 invocation of hook_search_api_algolia_objects_alter()
SearchApiAlgoliaBackend::alterAlgoliaObjects in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
Applies custom modifications to indexed Algolia objects.

File

./search_api_algolia.api.php, line 25
Hooks provided by the Search API Algolia search module.

Code

function hook_search_api_algolia_objects_alter(array &$objects, \Drupal\search_api\IndexInterface $index, array $items) {

  // Adds a "foo" field with value "bar" to all documents.
  foreach ($objects as $key => $object) {
    $objects[$key]['foo'] = 'bar';
  }
}