You are here

public function SearchApiSolrBackend::indexItems in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::indexItems()
  2. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::indexItems()
  3. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::indexItems()

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

Overrides BackendSpecificInterface::indexItems

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 980

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function indexItems(IndexInterface $index, array $items) {
  $connector = $this
    ->getSolrConnector();
  $update_query = $connector
    ->getUpdateQuery();
  $documents = $this
    ->getDocuments($index, $items, $update_query);
  if (!$documents) {
    return [];
  }
  try {
    $update_query
      ->addDocuments($documents);
    $connector
      ->update($update_query, $this
      ->getCollectionEndpoint($index));
    $field_names = $this
      ->getSolrFieldNames($index);
    $ret = [];
    foreach ($documents as $document) {
      $ret[] = $document
        ->getFields()[$field_names['search_api_id']];
    }
    \Drupal::state()
      ->set('search_api_solr.' . $index
      ->id() . '.last_update', \Drupal::time()
      ->getCurrentTime());
    return $ret;
  } catch (\Exception $e) {
    watchdog_exception('search_api_solr', $e, "%type while indexing: @message in %function (line %line of %file).");
    throw new SearchApiSolrException($e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}