You are here

public function FuzzySearchService::deleteItems in Fuzzy Search 7

Deletes indexed items from this server.

Might be either used to delete some items (given by their ids) from a specified index, or all items from that index, or all items from all indexes on this server.

Parameters

$ids: Either an array containing the ids of the items that should be deleted, or 'all' if all items should be deleted. Other formats might be recognized by implementing classes, but these are not standardized.

SearchApiIndex $index: The index from which items should be deleted, or NULL if all indexes on this server should be cleared (then, $ids has to be 'all').

Throws

SearchApiException If an error occurred while trying to delete the items.

Overrides SearchApiServiceInterface::deleteItems

1 call to FuzzySearchService::deleteItems()
FuzzySearchService::fieldsUpdated in includes/service.inc
Implements SearchApiServiceInterface::__construct().

File

includes/service.inc, line 614

Class

FuzzySearchService
Search service class using the database for storing index information.

Code

public function deleteItems($ids = 'all', SearchApiIndex $index = NULL) {
  if (!$index) {
    if (empty($this->options['indexes'])) {
      return;
    }
    $set = $this
      ->setDb();
    foreach ($this->options['indexes'] as $index) {
      foreach ($index as $fields) {

        // If you are using one or default fuzzysearch server it will
        // execute here.
        if (isset($fields['table']) && !empty($fields['table'])) {
          db_truncate($fields['table'], $this->queryOptions)
            ->execute();
        }
        else {

          // More than one server hits here.
          foreach ($fields as $field) {
            if (isset($field['table']) && !empty($field['table'])) {
              db_truncate($field['table'], $this->queryOptions)
                ->execute();
            }
          }
        }
      }
    }
    if ($set) {
      $this
        ->resetDb();
    }
    return;
  }
  if (empty($this->options['indexes'][$index->machine_name])) {
    return;
  }
  $set = $this
    ->setDb();
  foreach ($this->options['indexes'][$index->machine_name] as $field) {
    if (is_array($ids)) {
      db_delete($field['table'], $this->queryOptions)
        ->condition('item_id', $ids, 'IN')
        ->execute();
    }
    else {
      db_truncate($field['table'], $this->queryOptions)
        ->execute();
    }
  }
  if ($set) {
    $this
      ->resetDb();
  }
}