eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex::deleteWordsWithoutObjects PHP Method

deleteWordsWithoutObjects() public method

Delete words not related to any content object.
    public function deleteWordsWithoutObjects()
    {
        $query = $this->dbHandler->createDeleteQuery();
        $query->deleteFrom($this->dbHandler->quoteTable('ezsearch_word'))->where($query->expr->eq($this->dbHandler->quoteColumn('object_count'), ':c'));
        $stmt = $query->prepare();
        $stmt->execute(['c' => 0]);
    }

Usage Example

 /**
  * 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;
 }