Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SearchIndex.php

function SearchIndex::clear

1 call to SearchIndex::clear()
SearchIndex::index in core/modules/search/src/SearchIndex.php

File

core/modules/search/src/SearchIndex.php, line 198

Class

SearchIndex
Provides search index management functions.

Namespace

Drupal\search

Code

public function clear($type = NULL, $sid = NULL, $langcode = NULL) {
    try {
        $query_index = $this->connection
            ->delete('search_index');
        $query_dataset = $this->connection
            ->delete('search_dataset');
        if ($type) {
            $query_index->condition('type', $type);
            $query_dataset->condition('type', $type);
            if ($sid) {
                $query_index->condition('sid', $sid);
                $query_dataset->condition('sid', $sid);
                if ($langcode) {
                    $query_index->condition('langcode', $langcode);
                    $query_dataset->condition('langcode', $langcode);
                }
            }
        }
        $query_index->execute();
        $query_dataset->execute();
    } catch (\Exception $e) {
        throw new SearchIndexException("Failed to clear index for type '{$type}', sid '{$sid}' and langcode '{$langcode}'", 0, $e);
    }
    if ($type) {
        // Invalidate all render cache items that contain data from this index.
        $this->cacheTagsInvalidator
            ->invalidateTags([
            'search_index:' . $type,
        ]);
    }
    else {
        // Invalidate all render cache items that contain data from any index.
        $this->cacheTagsInvalidator
            ->invalidateTags([
            'search_index',
        ]);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal