public function SearchApiDbService::indexItems in Search API Database Search 7
Indexes the specified items.
Parameters
SearchApiIndex $index: The search index for which items should be indexed.
array $items: An array of items to be indexed, keyed by their id. The values are associative arrays of the fields to be stored, where each field is an array with the following keys:
- type: One of the data types recognized by the Search API, or the special type "tokens" for fulltext fields.
- original_type: The original type of the property, as defined by the datasource controller for the index's item type.
- value: The value to index.
The special field "search_api_language" contains the item's language and should always be indexed.
The value of fields with the "tokens" type is an array of tokens. Each token is an array containing the following keys:
- value: The word that the token represents.
- score: A score for the importance of that word.
Return value
array An array of the ids of all items that were successfully indexed.
Throws
SearchApiException If indexing was prevented by a fundamental configuration error.
Overrides SearchApiServiceInterface::indexItems
File
- ./
service.inc, line 814 - Contains SearchApiDbService.
Class
- SearchApiDbService
- Indexes and searches items using the database.
Code
public function indexItems(SearchApiIndex $index, array $items) {
if (empty($this->options['indexes'][$index->machine_name])) {
throw new SearchApiException(t('No field settings for index with id @id.', array(
'@id' => $index->machine_name,
)));
}
$indexed = array();
foreach ($items as $id => $item) {
try {
$this
->indexItem($index, $id, $item);
$indexed[] = $id;
} catch (Exception $e) {
// We just log the error, hoping we can index the other items.
$vars['%item_id'] = $id;
$vars['%index'] = $index->name;
watchdog_exception('search_api_db', $e, '%type while trying to index item %item_id on index %index: !message in %function (line %line of %file).', $vars);
}
}
return $indexed;
}