You are here

function hook_search_api_index_items_alter in Search API 8

Same name and namespace in other branches
  1. 7 search_api.api.php \hook_search_api_index_items_alter()

Allows you to log or alter the items that are indexed.

Please be aware that generally preventing the indexing of certain items is deprecated. This is better done with processors, which can easily be configured and only added to indexes where this behaviour is wanted. If your module will use this hook to reject certain items from indexing, please document this clearly to avoid confusion.

Parameters

\Drupal\search_api\IndexInterface $index: The search index on which items will be indexed.

\Drupal\search_api\Item\ItemInterface[] $items: The items that will be indexed.

Deprecated

in search_api:8.x-1.14 and is removed from search_api:2.0.0. Please use the "search_api.indexing_items" event instead.

See also

https://www.drupal.org/node/3059866

1 function implements hook_search_api_index_items_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

search_api_test_hooks_search_api_index_items_alter in tests/search_api_test_hooks/search_api_test_hooks.search_api.inc
Implements hook_search_api_index_items_alter().
1 invocation of hook_search_api_index_items_alter()
BackendTest::indexItemDirectly in modules/search_api_db/tests/src/Kernel/BackendTest.php
Indexes an item directly.

File

./search_api.api.php, line 284
Hooks provided by the Search API module.

Code

function hook_search_api_index_items_alter(\Drupal\search_api\IndexInterface $index, array &$items) {
  foreach ($items as $item_id => $item) {
    list(, $raw_id) = \Drupal\search_api\Utility\Utility::splitCombinedId($item
      ->getId());
    if ($raw_id % 5 == 0) {
      unset($items[$item_id]);
    }
  }
  $arguments = [
    '%index' => $index
      ->label(),
    '@ids' => implode(', ', array_keys($items)),
  ];
  $message = t('Indexing items on index %index with the following IDs: @ids', $arguments);
  \Drupal::messenger()
    ->addStatus($message);
}