You are here

public function SearchApiSolrBackend::deleteAllIndexItems in Search API Solr 8

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

Deletes all the items from the index.

Parameters

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

string|null $datasource_id: (optional) If given, only delete items from the datasource with the given ID.

Throws

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

Overrides BackendSpecificInterface::deleteAllIndexItems

1 call to SearchApiSolrBackend::deleteAllIndexItems()
SearchApiSolrBackend::removeIndex in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Removes an index from this server.

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function deleteAllIndexItems(IndexInterface $index, $datasource_id = NULL) {

  // Since the index ID we use for indexing can contain arbitrary
  // prefixes, we have to escape it for use in the query.
  $connector = $this
    ->getSolrConnector();
  $query_helper = $connector
    ->getQueryHelper();
  $query = '+index_id:' . $this
    ->getIndexId($query_helper
    ->escapePhrase($index
    ->id()));
  $query .= ' +hash:' . $query_helper
    ->escapePhrase(SearchApiSolrUtility::getSiteHash());
  if ($datasource_id) {
    $query .= ' +' . $this
      ->getSolrFieldNames($index)['search_api_datasource'] . ':' . $query_helper
      ->escapePhrase($datasource_id);
  }
  $update_query = $connector
    ->getUpdateQuery();
  $update_query
    ->addDeleteQuery($query);
  $connector
    ->update($update_query);
}