Skip to content

Commit

Permalink
EZP-30296: Introduced bulk document deleting using deleteByQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadejski committed Sep 24, 2019
1 parent af22427 commit caee711
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
*/
class Handler implements SearchHandlerInterface, Capable
{
const SOLR_BULK_REMOVE_LIMIT = 1000;

/**
* Content locator gateway.
*
Expand Down Expand Up @@ -340,9 +342,15 @@ protected function deleteAllItemsWithoutAdditionalLocation($locationId)
$this->gateway->searchAllEndpoints($query)
);

$contentDocumentIds = [];

foreach ($searchResult->searchHits as $hit) {
$idPrefix = $this->mapper->generateContentDocumentId($hit->valueObject->id);
$this->gateway->deleteByQuery("_root_:{$idPrefix}*");
$contentDocumentIds[] = $this->mapper->generateContentDocumentId($hit->valueObject->id) . '*';
}

foreach (\array_chunk($contentDocumentIds, self::SOLR_BULK_REMOVE_LIMIT) as $ids) {
$query = '_root_:(' . implode(' OR ', $ids) . ')';
$this->gateway->deleteByQuery($query);
}
}

Expand Down

0 comments on commit caee711

Please sign in to comment.