You are here

protected function SolrCommitTrait::ensureCommit in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 src/Utility/SolrCommitTrait.php \Drupal\search_api_solr\Utility\SolrCommitTrait::ensureCommit()
  2. 8.2 src/Utility/SolrCommitTrait.php \Drupal\search_api_solr\Utility\SolrCommitTrait::ensureCommit()
  3. 4.x src/Utility/SolrCommitTrait.php \Drupal\search_api_solr\Utility\SolrCommitTrait::ensureCommit()

Explicitly sends a commit command to a Solr server.

Parameters

\Drupal\search_api\IndexInterface $index: The Search API server entity.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

16 calls to SolrCommitTrait::ensureCommit()
FacetsTest::indexItems in tests/src/Functional/FacetsTest.php
Indexes all (unindexed) items on the specified index.
FacetsTest::tearDown in tests/src/Functional/FacetsTest.php
IntegrationTest::indexItems in tests/src/Functional/IntegrationTest.php
Indexes all (unindexed) items on the specified index.
IntegrationTest::tearDown in tests/src/Functional/IntegrationTest.php
IntegrationTest::testInstallAndDefaultSetupWorking in modules/search_api_solr_defaults/tests/src/Functional/IntegrationTest.php
Tests whether the default search was correctly installed.

... See full list

File

src/Utility/SolrCommitTrait.php, line 23

Class

SolrCommitTrait
Helper to ensure that solr index is up to date.

Namespace

Drupal\search_api_solr\Utility

Code

protected function ensureCommit(IndexInterface $index) {
  if ($server = $index
    ->getServerInstance()) {

    /** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
    $backend = $server
      ->getBackend();

    /** @var \Drupal\search_api_solr\SolrConnectorInterface $connector */
    $connector = $backend
      ->getSolrConnector();
    $update = $connector
      ->getUpdateQuery();
    $update
      ->addCommit(TRUE, TRUE, TRUE);
    $connector
      ->update($update, $backend
      ->getCollectionEndpoint($index));
    if (SOLR_INDEX_WAIT) {
      sleep(SOLR_INDEX_WAIT);
    }
  }
}