You are here

public function SearchApiSolrConnection::addDocuments in Search API Solr 7

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

Parameters

array $documents: Should be an array of ApacheSolrDocument instances

bool $overwrite: (optional) Set whether existing documents with the same IDs should be overwritten. Defaults to TRUE.

bool $commitWithin: (optional) The time in which the indexed documents should be committed to the index, in milliseconds. This works in addition to the Solr server's auto commit settings. Defaults to no additional handling.

Return value

object A response object.

Throws

SearchApiException If an error occurs during the service call.

Overrides SearchApiSolrConnectionInterface::addDocuments

File

includes/solr_connection.inc, line 779

Class

SearchApiSolrConnection
Represents a Solr server resource.

Code

public function addDocuments(array $documents, $overwrite = NULL, $commitWithin = NULL) {
  $attr = '';
  if (isset($overwrite)) {
    $attr .= ' overwrite="' . ($overwrite ? 'true"' : 'false"');
  }
  if (isset($commitWithin)) {
    $attr .= ' commitWithin="' . (int) $commitWithin . '"';
  }
  $rawPost = "<add{$attr}>";
  foreach ($documents as $document) {
    if (is_object($document) && $document instanceof SearchApiSolrDocument) {
      $rawPost .= $document
        ->toXml();
    }
  }
  $rawPost .= '</add>';
  return $this
    ->update($rawPost);
}