public function TestBackend::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
- tests/
search_api_test/ src/ Plugin/ search_api/ backend/ TestBackend.php, line 122
Class
- TestBackend
- Provides a dummy backend for testing purposes.
Namespace
Drupal\search_api_test\Plugin\search_api\backendCode
public function indexItems(IndexInterface $index, array $items) {
if ($override = $this
->getMethodOverride(__FUNCTION__)) {
return call_user_func($override, $this, $index, $items);
}
$this
->checkError(__FUNCTION__);
$state = \Drupal::state();
$key = 'search_api_test.backend.indexed.' . $index
->id();
$indexed_values = $state
->get($key, []);
$skip = $state
->get('search_api_test.backend.indexItems.skip', []);
$skip = array_flip($skip);
/** @var \Drupal\search_api\Item\ItemInterface $item */
foreach ($items as $id => $item) {
if (isset($skip[$id])) {
unset($items[$id]);
continue;
}
$indexed_values[$id] = [];
foreach ($item
->getFields() as $field_id => $field) {
$indexed_values[$id][$field_id] = $field
->getValues();
}
}
$state
->set($key, $indexed_values);
return array_keys($items);
}