You are here

protected function BackendTest::indexItemDirectly in Search API 8

Indexes an item directly.

Parameters

\Drupal\search_api\IndexInterface $index: The search index to index the item on.

\Drupal\search_api\Item\ItemInterface $item: The item.

Return value

string[] The successfully indexed IDs.

Throws

\Drupal\search_api\SearchApiException Thrown if indexing failed.

1 call to BackendTest::indexItemDirectly()
BackendTest::regressionTest2938646 in modules/search_api_db/tests/src/Kernel/BackendTest.php
Tests indexing of items with boost.

File

modules/search_api_db/tests/src/Kernel/BackendTest.php, line 972

Class

BackendTest
Tests index and search capabilities using the Database search backend.

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function indexItemDirectly(IndexInterface $index, ItemInterface $item) {
  $items = [
    $item
      ->getId() => $item,
  ];

  // Minimalistic version of code copied from
  // \Drupal\search_api\Entity\Index::indexSpecificItems().
  $index
    ->alterIndexedItems($items);
  \Drupal::moduleHandler()
    ->alter('search_api_index_items', $index, $items);
  $event = new IndexingItemsEvent($index, $items);
  \Drupal::getContainer()
    ->get('event_dispatcher')
    ->dispatch(SearchApiEvents::INDEXING_ITEMS, $event);
  foreach ($items as $item) {

    // This will cache the extracted fields so processors, etc., can retrieve
    // them directly.
    $item
      ->getFields();
  }
  $index
    ->preprocessIndexItems($items);
  $indexed_ids = [];
  if ($items) {
    $indexed_ids = $index
      ->getServerInstance()
      ->indexItems($index, $items);
  }
  return $indexed_ids;
}