In the first step we delete an existing entry in the SOLR index using the table name and the identifier:
// Delete SOLR entry
$garbageCollector = GeneralUtility::makeInstance(GarbageHandler::class);
$garbageCollector->collectGarbage('tx_ext_domain_model_product', $product->getUid());
After the import, we can create a new entry in the index queue table of the SOLR extension:
// Add to queue
$queryBuilder = DatabaseUtility::getQueryBuilderForTable('tx_solr_indexqueue_item');
$queryBuilder
->insert('tx_solr_indexqueue_item')
->values([
'root' => 1,
'item_type' => 'tx_ext_domain_model_product',
'item_uid' => $product->getUid(),
'indexing_configuration' => 'products',
'changed' => time(),
'errors' => '',
])
->execute();
Explanation: root => PID of site-config, item_type: table name, item_uid: record identifier, indexing_configuration: name of indexconfiguration (see TypoScript)
Note: If you're wondering why we enter the data directly into the table and don't use a ready-made function from the SOLR extension: There is the add() function in the class \ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueItemRepository, here. However, there is a note that this is only there for internal purposes and should not be used from outside.