You are here

public function DrupalApacheSolrService::optimize in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::optimize()
  2. 7 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::optimize()

Send an optimize command. Will be synchronous unless both wait parameters are set to false.

Parameters

boolean $waitFlush: block until index changes are flushed to disk Removed in Solr 4.0

boolean $waitSearcher: block until a new searcher is opened and registered as the main query searcher, making the changes visible.

float $timeout: Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)

Return value

response object

Throws

Exception If an error occurs during the service call

Overrides DrupalApacheSolrServiceInterface::optimize

File

./Drupal_Apache_Solr_Service.php, line 813

Class

DrupalApacheSolrService
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Code

public function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600) {
  $flushValue = $waitFlush ? 'true' : 'false';
  $searcherValue = $waitSearcher ? 'true' : 'false';
  $softCommit = $this->soft_commit ? 'true' : 'false';
  $solr_version = $this
    ->getSolrVersion();
  if ($solr_version <= 3) {
    $rawPost = '<optimize waitSearcher="' . $searcherValue . '" waitFlush="' . $flushValue . '" />';
  }
  else {
    $rawPost = '<optimize waitSearcher="' . $searcherValue . '" softCommit="' . $softCommit . '" />';
  }
  return $this
    ->update($rawPost, $timeout);
}