function NodeSearch::indexStatus

Same name and namespace in other branches
  1. 8.9.x core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::indexStatus()
  2. 10 core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::indexStatus()
  3. 11.x core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::indexStatus()

Reports the status of indexing.

The core search module only invokes this method on active module plugins. Implementing modules do not need to check whether they are active when calculating their return values.

Return value

array An associative array with the key-value pairs:

  • remaining: The number of items left to index.
  • total: The total number of items to index.

Overrides SearchIndexingInterface::indexStatus

File

core/modules/node/src/Plugin/Search/NodeSearch.php, line 560

Class

NodeSearch
Handles searching for node entities using the Search module index.

Namespace

Drupal\node\Plugin\Search

Code

public function indexStatus() {
    $total = $this->database
        ->query('SELECT COUNT(*) FROM {node}')
        ->fetchField();
    $remaining = $this->database
        ->query("SELECT COUNT(DISTINCT [n].[nid]) FROM {node} [n] LEFT JOIN {search_dataset} [sd] ON [sd].[sid] = [n].[nid] AND [sd].[type] = :type WHERE [sd].[sid] IS NULL OR [sd].[reindex] <> 0", [
        ':type' => $this->getPluginId(),
    ])
        ->fetchField();
    return [
        'remaining' => $remaining,
        'total' => $total,
    ];
}

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