You are here

public function DrupalApacheSolrService::commit in Apache Solr Search 7

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

Send a commit command. Will be synchronous unless both wait parameters are set to false.

Parameters

boolean $optimize Defaults to true: optimizes the index files. Only valid for solr versions <= 3

boolean $waitFlush: block until index changes are flushed to disk. Only valid for solr versions <= 3

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::commit

File

./Drupal_Apache_Solr_Service.php, line 780

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 commit($optimize = TRUE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600) {
  $optimizeValue = $optimize ? 'true' : 'false';
  $flushValue = $waitFlush ? 'true' : 'false';
  $searcherValue = $waitSearcher ? 'true' : 'false';
  $softCommit = $this->soft_commit ? 'true' : 'false';
  $solr_version = $this
    ->getSolrVersion();
  if ($solr_version <= 3) {
    $rawPost = '<commit waitSearcher="' . $searcherValue . '" waitFlush="' . $flushValue . '" optimize="' . $optimizeValue . '" />';
  }
  else {
    $rawPost = '<commit waitSearcher="' . $searcherValue . '" softCommit="' . $softCommit . '" />';
  }
  $response = $this
    ->update($rawPost, $timeout);
  $this
    ->_clearCache();
  return $response;
}