SolrCommitTrait.php in Search API Solr 8.2
Same filename and directory in other branches
Namespace
Drupal\search_api_solr\UtilityFile
src/Utility/SolrCommitTrait.phpView source
<?php
namespace Drupal\search_api_solr\Utility;
use Drupal\search_api\ServerInterface;
defined('SOLR_INDEX_WAIT') || define('SOLR_INDEX_WAIT', getenv('SOLR_INDEX_WAIT') ?: 0);
/**
* Helper to ensure that solr index is up to date.
*/
trait SolrCommitTrait {
/**
* Explicitly sent a commit command to a Solr server.
*
* @param \Drupal\search_api\ServerInterface $server
*
* @throws \Drupal\search_api\SearchApiException
*/
protected function ensureCommit(ServerInterface $server) {
$backend = $server
->getBackend();
/** @var \Drupal\search_api_solr\SolrConnectorInterface $connector */
$connector = $backend
->getSolrConnector();
$update = $connector
->getUpdateQuery();
$update
->addCommit(TRUE, TRUE, TRUE);
$connector
->update($update);
if (SOLR_INDEX_WAIT) {
sleep(SOLR_INDEX_WAIT);
}
}
}
Traits
Name![]() |
Description |
---|---|
SolrCommitTrait | Helper to ensure that solr index is up to date. |