You are here

public function Database::indexItems in Search API 8

Indexes the specified items.

Parameters

\Drupal\search_api\IndexInterface $index: The search index for which items should be indexed.

\Drupal\search_api\Item\ItemInterface[] $items: An array of items to be indexed, keyed by their item IDs.

Return value

string[] The IDs of all items that were successfully indexed.

Throws

\Drupal\search_api\SearchApiException Thrown if indexing was prevented by a fundamental configuration error.

Overrides BackendSpecificInterface::indexItems

File

modules/search_api_db/src/Plugin/search_api/backend/Database.php, line 1197

Class

Database
Indexes and searches items using the database.

Namespace

Drupal\search_api_db\Plugin\search_api\backend

Code

public function indexItems(IndexInterface $index, array $items) {
  if (!$this
    ->getIndexDbInfo($index)) {
    $index_id = $index
      ->id();
    throw new SearchApiException("No field settings saved for index with ID '{$index_id}'.");
  }
  $indexed = [];
  foreach ($items as $id => $item) {
    try {
      $this
        ->indexItem($index, $item);
      $indexed[] = $id;
    } catch (\Exception $e) {

      // We just log the error, hoping we can index the other items.
      $this
        ->getLogger()
        ->warning($e
        ->getMessage());
    }
  }
  return $indexed;
}