public function SearchApiSolrService::deleteItems in Search API Solr 7
Implements SearchApiServiceInterface::deleteItems().
This method has a custom, Solr-specific extension:
If $ids is a string other than "all", it is treated as a Solr query. All items matching that Solr query are then deleted. If $index is additionally specified, then only those items also lying on that index will be deleted.
It is up to the caller to ensure $ids is a valid query when the method is called in this fashion.
Parameters
array|string $ids: Either an array containing the ids of the items that should be deleted, or 'all' if all items should be deleted. Other formats might be recognized by implementing classes, but these are not standardized.
SearchApiIndex $index: The index from which items should be deleted, or NULL if all indexes on this server should be cleared (then, $ids has to be 'all').
Throws
SearchApiException If an error occurred while trying to delete the items.
Overrides SearchApiServiceInterface::deleteItems
File
- includes/
service.inc, line 854
Class
- SearchApiSolrService
- Search service class using Solr server.
Code
public function deleteItems($ids = 'all', SearchApiIndex $index = NULL) {
$this
->connect();
if (is_array($ids)) {
$index_id = $this
->getIndexId($index->machine_name);
$solr_ids = array();
foreach ($ids as $id) {
$solr_ids[] = $this
->createId($index_id, $id);
}
$this->solr
->deleteByMultipleIds($solr_ids);
}
else {
$query = array();
if ($index) {
$index_id = $this
->getIndexId($index->machine_name);
$index_id = call_user_func(array(
$this
->getConnectionClass(),
'phrase',
), $index_id);
$query[] = "index_id:{$index_id}";
}
if (!empty($this->options['site_hash'])) {
// We don't need to escape the site hash, as that consists only of
// alphanumeric characters.
$query[] = 'hash:' . search_api_solr_site_hash();
}
if ($ids != 'all') {
$query[] = $query ? "({$ids})" : $ids;
}
$this->solr
->deleteByQuery($query ? implode(' AND ', $query) : '*:*');
}
$this
->scheduleCommit();
}