function SearchIndex::markForReindex

Same name and namespace in other branches
  1. 8.9.x core/modules/search/src/SearchIndex.php \Drupal\search\SearchIndex::markForReindex()
  2. 10 core/modules/search/src/SearchIndex.php \Drupal\search\SearchIndex::markForReindex()
  3. 11.x core/modules/search/src/SearchIndex.php \Drupal\search\SearchIndex::markForReindex()

Changes the timestamp on indexed items to 'now' to force reindexing.

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

Parameters

string $type: (optional) The plugin ID or other machine-readable type of this item. If omitted, the entire search index is marked for reindexing, and $sid and $langcode are ignored.

int $sid: (optional) An ID number identifying this particular item (e.g., node ID). If omitted, everything matching $type is marked, and $langcode is ignored.

string $langcode: (optional) The language code to mark. If omitted, everything matching $type and $sid is marked.

Overrides SearchIndexInterface::markForReindex

File

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

Class

SearchIndex
Provides search index management functions.

Namespace

Drupal\search

Code

public function markForReindex($type = NULL, $sid = NULL, $langcode = NULL) {
    try {
        $query = $this->connection
            ->update('search_dataset')
            ->fields([
            'reindex' => REQUEST_TIME,
        ])
            ->condition('reindex', 0);
        if ($type) {
            $query->condition('type', $type);
            if ($sid) {
                $query->condition('sid', $sid);
                if ($langcode) {
                    $query->condition('langcode', $langcode);
                }
            }
        }
        $query->execute();
    } catch (\Exception $e) {
        throw new SearchIndexException("Failed to mark index for re-indexing for type '{$type}', sid '{$sid}' and langcode '{$langcode}'", 0, $e);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.