public function SearchApiSolrBackend::indexItems in Search API Solr 8
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::indexItems()
- 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::indexItems()
- 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::indexItems()
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
- src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php, line 702
Class
- SearchApiSolrBackend
- Apache Solr backend for search api.
Namespace
Drupal\search_api_solr\Plugin\search_api\backendCode
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);
$ret = [];
foreach ($documents as $document) {
$ret[] = $document
->getFields()[SEARCH_API_ID_FIELD_NAME];
}
return $ret;
} catch (\Exception $e) {
watchdog_exception('search_api_solr', $e, "%type while indexing: @message in %function (line %line of %file).");
throw new SearchApiException($e
->getMessage(), $e
->getCode(), $e);
}
}