public function Database::updateIndex in Search API 8
Notifies the server that an index attached to it has been changed.
If any user action is necessary as a result of this, the method should set a message to notify the user.
Parameters
\Drupal\search_api\IndexInterface $index: The updated index.
Throws
\Drupal\search_api\SearchApiException Thrown if an error occurred while reacting to the change.
Overrides BackendPluginBase::updateIndex
File
- modules/
search_api_db/ src/ Plugin/ search_api/ backend/ Database.php, line 671
Class
- Database
- Indexes and searches items using the database.
Namespace
Drupal\search_api_db\Plugin\search_api\backendCode
public function updateIndex(IndexInterface $index) {
// Process field ID changes so they won't lead to reindexing.
$renames = $index
->getFieldRenames();
if ($renames) {
$db_info = $this
->getIndexDbInfo($index);
// We have to recreate "field_tables" from scratch in case field IDs got
// swapped between two (or more) fields.
$fields = [];
foreach ($db_info['field_tables'] as $field_id => $info) {
if (isset($renames[$field_id])) {
$field_id = $renames[$field_id];
}
$fields[$field_id] = $info;
}
if ($fields != $db_info['field_tables']) {
$db_info['field_tables'] = $fields;
$this
->getKeyValueStore()
->set($index
->id(), $db_info);
}
}
// Check if any fields were updated and trigger a reindex if needed.
if ($this
->fieldsUpdated($index)) {
$index
->reindex();
}
}