You are here

public function SearchApiSolrBackend::deleteItems in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::deleteItems()
  2. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::deleteItems()
  3. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::deleteItems()

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

Overrides BackendSpecificInterface::deleteItems

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 1147

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function deleteItems(IndexInterface $index, array $ids) {
  try {
    $index_id = $this
      ->getTargetedIndexId($index);
    $site_hash = $this
      ->getTargetedSiteHash($index);
    $solr_ids = [];
    foreach ($ids as $id) {
      $solr_ids[] = $this
        ->createId($site_hash, $index_id, $id);
    }
    $connector = $this
      ->getSolrConnector();
    $update_query = $connector
      ->getUpdateQuery();
    $update_query
      ->addDeleteByIds($solr_ids);
    $connector
      ->update($update_query, $this
      ->getCollectionEndpoint($index));
    \Drupal::state()
      ->set('search_api_solr.' . $index
      ->id() . '.last_update', \Drupal::time()
      ->getCurrentTime());
  } catch (ExceptionInterface $e) {
    throw new SearchApiSolrException($e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}