You are here

function search_index_clear in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/search/search.module \search_index_clear()

Clears either a part of, or the entire search index.

This function is meant for use by search page plugins, or for building a user interface that lets users clear all or parts of the search index.

Parameters

string|null $type: (optional) The plugin ID or other machine-readable type for the items to remove from the search index. If omitted, $sid and $langcode are ignored and the entire search index is cleared.

string|null $sid: (optional) The ID of the items to remove from the search index. If omitted, all items matching $type are cleared, and $langcode is ignored.

string|null $langcode: (optional) Language code of the item to remove from the search index. If omitted, all items matching $sid and $type are cleared.

4 calls to search_index_clear()
Node::preDelete in core/modules/node/src/Entity/Node.php
Acts on entities before they are deleted and before hooks are invoked.
NodeSearch::indexClear in core/modules/node/src/Plugin/Search/NodeSearch.php
Clears the search index for this plugin.
SearchMultilingualEntityTest::testMultilingualSearch in core/modules/search/src/Tests/SearchMultilingualEntityTest.php
Tests the indexing throttle and search results with multilingual nodes.
search_index in core/modules/search/search.module
Updates the full-text search index for a particular item.

File

core/modules/search/search.module, line 134
Enables site-wide keyword searching.

Code

function search_index_clear($type = NULL, $sid = NULL, $langcode = NULL) {
  $query_index = db_delete('search_index');
  $query_dataset = db_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();
  if ($type) {

    // Invalidate all render cache items that contain data from this index.
    Cache::invalidateTags([
      'search_index:' . $type,
    ]);
  }
  else {

    // Invalidate all render cache items that contain data from any index.
    Cache::invalidateTags([
      'search_index',
    ]);
  }
}