You are here

public function SolrConnectorPluginBase::optimize in Search API Solr 4.x

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. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::optimize()

Optimizes the Solr index.

Parameters

\Solarium\Core\Client\Endpoint|null $endpoint: (optional) The Solarium endpoint object.

Throws

\Drupal\search_api_solr\SearchApiSolrException

Overrides SolrConnectorInterface::optimize

File

src/SolrConnector/SolrConnectorPluginBase.php, line 1045

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();
  }

  // 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.
  $this
    ->useTimeout(self::OPTIMIZE_TIMEOUT, $endpoint);
  $update_query = $this->solr
    ->createUpdate();
  $update_query
    ->addOptimize(TRUE, FALSE);
  $this
    ->execute($update_query, $endpoint);
}