public function SearchApiDbService::addIndex in Search API Database Search 7
Implements SearchApiServiceInterface::__construct().
Does nothing, by default.
Overrides SearchApiAbstractService::addIndex
File
- ./
service.inc, line 276 - Contains SearchApiDbService.
Class
- SearchApiDbService
- Indexes and searches items using the database.
Code
public function addIndex(SearchApiIndex $index) {
try {
// If there are no fields, we can take a shortcut.
if (!isset($index->options['fields'])) {
if (!isset($this->options['indexes'][$index->machine_name])) {
$this->options['indexes'][$index->machine_name] = array();
$this->server
->save();
}
elseif ($this->options['indexes'][$index->machine_name]) {
$this
->removeIndex($index);
$this->options['indexes'][$index->machine_name] = array();
$this->server
->save();
}
return;
}
$this->options += array(
'indexes' => array(),
);
$this->options['indexes'] += array(
$index->machine_name => array(),
);
} catch (Exception $e) {
throw new SearchApiException($e
->getMessage());
}
// If dealing with features or stale data or whatever, we might already have
// settings stored for this index. If we have, we should take care to only
// change what is needed, so we don't save the server (potentially setting
// it to "Overridden") unnecessarily.
// The easiest way to do this is by just pretending the index was already
// present, but its fields were updated.
$this
->fieldsUpdated($index);
}