You are here

public function SearchApiDbService::removeIndex in Search API Database Search 7

Implements SearchApiServiceInterface::__construct().

By default, removes all items from that index.

Overrides SearchApiAbstractService::removeIndex

1 call to SearchApiDbService::removeIndex()
SearchApiDbService::addIndex in ./service.inc
Implements SearchApiServiceInterface::__construct().

File

./service.inc, line 785
Contains SearchApiDbService.

Class

SearchApiDbService
Indexes and searches items using the database.

Code

public function removeIndex($index) {
  try {
    $id = is_object($index) ? $index->machine_name : $index;
    if (!isset($this->options['indexes'][$id])) {
      return;
    }

    // Don't delete the index data of read-only indexes!
    if (!is_object($index) || empty($index->read_only)) {
      foreach ($this->options['indexes'][$id] as $field) {

        // Some fields share a de-normalized table, brute force since
        // everything is going.
        if ($this->connection
          ->schema()
          ->tableExists($field['table'])) {
          $this->connection
            ->schema()
            ->dropTable($field['table']);
        }
      }
    }
    unset($this->options['indexes'][$id]);
    $this->server
      ->save();
  } catch (Exception $e) {
    throw new SearchApiException($e
      ->getMessage());
  }
}