Delete Solr entries in TYPO3

07. Februar 2024TYPO3Solr

This is how you can delete outdated data from Solr in TYPO3. For example all events which lay in the past.

The extension Apache Solr for TYPO3 provides the abstract class ApacheSolrForTypo3\Solr\Domain\Index\Queue\GarbageRemover\AbstractStrategy.
You can create a class ExampleStrategy which extends this class and implement the protected method removeGarbageOfByStrategy() like below:

 * @throws UnexpectedTYPO3SiteInitializationException
 * @throws Exception
protected function removeGarbageOfByStrategy(string $table, int $uid): void
    $this->deleteInSolrAndUpdateIndexQueue($table, $uid);

In a CLI script or a DataHandler hook you can create an instance of your class

$exampleStrategy = GeneralUtility::makeInstance(ExampleStrategy::class);

and execute the public method removeGarbageOf() which will call your removeGarbageOfByStrategy():

$exampleStrategy->removeGarbageOf($table, $uidOfTheRecordYouWantToDelete);