You are here

public function SolrConnectorPluginBase::optimize in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::optimize()
  2. 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::optimize()
  3. 4.x src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::optimize()

Optimizes the Solr index.

Parameters

\Solarium\Core\Client\Endpoint|null $endpoint:

Overrides SolrConnectorInterface::optimize

File

src/SolrConnector/SolrConnectorPluginBase.php, line 889

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function optimize(Endpoint $endpoint = NULL) {
  $this
    ->connect();
  if (!$endpoint) {
    $endpoint = $this->solr
      ->getEndpoint('core');
  }

  // The default timeout is set for search queries. The configured timeout
  // might differ and needs to be set now because solarium doesn't
  // distinguish between these types.
  $timeout = $endpoint
    ->getTimeout();
  $endpoint
    ->setTimeout($this->configuration['optimize_timeout']);
  $update_query = $this->solr
    ->createUpdate();
  $update_query
    ->addOptimize(TRUE, FALSE);
  $this
    ->execute($update_query, $endpoint);

  // Reset the timeout setting to the default value for search queries.
  $endpoint
    ->setTimeout($timeout);
}