/**
* Remove whole content or a specific version from index.
*
* Ported from the legacy code
* @see https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L386
*
* @param mixed $contentId
* @param mixed|null $versionId
*
* @return bool
*/
public function remove($contentId, $versionId = null)
{
$doDelete = false;
$this->dbHandler->beginTransaction();
// fetch all the words and decrease the object count on all the words
$wordIDList = $this->searchIndex->getContentObjectWords($contentId);
if (count($wordIDList) > 0) {
$this->searchIndex->decrementWordObjectCount($wordIDList);
$doDelete = true;
}
if ($doDelete) {
$this->searchIndex->deleteWordsWithoutObjects();
$this->searchIndex->deleteObjectWordsLink($contentId);
}
$this->dbHandler->commit();
return true;
}