You are here

public function TestBackend::deleteItems in Search API 8

Deletes the specified items from the index.

Parameters

\Drupal\search_api\IndexInterface $index: The index from which items should be deleted.

string[] $item_ids: The IDs of the deleted items.

Throws

\Drupal\search_api\SearchApiException Thrown if an error occurred while trying to delete the items.

Overrides BackendSpecificInterface::deleteItems

File

tests/search_api_test/src/Plugin/search_api/backend/TestBackend.php, line 186

Class

TestBackend
Provides a dummy backend for testing purposes.

Namespace

Drupal\search_api_test\Plugin\search_api\backend

Code

public function deleteItems(IndexInterface $index, array $item_ids) {
  if ($override = $this
    ->getMethodOverride(__FUNCTION__)) {
    call_user_func($override, $this, $index, $item_ids);
    return;
  }
  $this
    ->checkError(__FUNCTION__);
  $state = \Drupal::state();
  $key = 'search_api_test.backend.indexed.' . $index
    ->id();
  $indexed_values = $state
    ->get($key, []);

  /** @var \Drupal\search_api\Item\ItemInterface $item */
  foreach ($item_ids as $item_id) {
    unset($indexed_values[$item_id]);
  }
  $state
    ->set($key, $indexed_values);
}