You are here

public function DrupalApacheSolrService::addDocuments in Apache Solr Search 8

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

Add an array of Solr Documents to the index all at once

Parameters

array $documents Should be an array of ApacheSolrDocument instances:

boolean $allowDups:

boolean $overwritePending:

boolean $overwriteCommitted:

Return value

response objecte

Throws

Exception If an error occurs during the service call

Overrides DrupalApacheSolrServiceInterface::addDocuments

File

./Drupal_Apache_Solr_Service.php, line 692

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 addDocuments($documents, $overwrite = NULL, $commitWithin = NULL) {
  $attr = '';
  if (isset($overwrite)) {
    $attr .= ' overwrite="' . empty($overwrite) ? 'false"' : 'true"';
  }
  if (isset($commitWithin)) {
    $attr .= ' commitWithin="' . intval($commitWithin) . '"';
  }
  $rawPost = "<add{$attr}>";
  foreach ($documents as $document) {
    if (is_object($document) && $document instanceof ApacheSolrDocument) {
      $rawPost .= ApacheSolrDocument::documentToXml($document);
    }
  }
  $rawPost .= '</add>';
  return $this
    ->update($rawPost);
}