You are here

public function Database::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

modules/search_api_db/src/Plugin/search_api/backend/Database.php, line 1558

Class

Database
Indexes and searches items using the database.

Namespace

Drupal\search_api_db\Plugin\search_api\backend

Code

public function deleteItems(IndexInterface $index, array $item_ids) {
  try {
    $db_info = $this
      ->getIndexDbInfo($index);
    if (empty($db_info['field_tables'])) {
      return;
    }
    foreach ($db_info['field_tables'] as $field) {
      $this->database
        ->delete($field['table'])
        ->condition('item_id', $item_ids, 'IN')
        ->execute();
    }

    // Delete the denormalized field data.
    $this->database
      ->delete($db_info['index_table'])
      ->condition('item_id', $item_ids, 'IN')
      ->execute();
  } catch (\Exception $e) {

    // The database operations might throw PDO or other exceptions, so we
    // catch them all and re-wrap them appropriately.
    throw new SearchApiException($e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}