You are here

public function CommandHelper::indexStatusCommand in Search API 8

Lists all search indexes with their status.

Parameters

string[]|null $indexId: (optional) An array of search index IDs, or NULL to list the status of all indexes.

Return value

array An associative array, keyed by search index ID, each value an associative array with the following keys:

  • id: The ID of the search index.
  • name: The human readable name of the search index.
  • complete: a percentage of indexation.
  • indexed: The amount of indexed items.
  • total: The total amount of items.

Throws

\Drupal\search_api\SearchApiException Thrown if one of the affected indexes had an invalid tracker set.

File

src/Utility/CommandHelper.php, line 171

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

public function indexStatusCommand(array $indexId = NULL) {
  $indexes = $this
    ->loadIndexes($indexId);
  if (!$indexes) {
    return [];
  }
  $rows = [];
  foreach ($indexes as $index) {
    $indexed = $index
      ->getTrackerInstance()
      ->getIndexedItemsCount();
    $total = $index
      ->getTrackerInstance()
      ->getTotalItemsCount();
    $complete = '-';
    if ($total > 0) {
      $complete = 100 * round($indexed / $total, 3) . '%';
    }
    $rows[$index
      ->id()] = [
      'id' => $index
        ->id(),
      'name' => $index
        ->label(),
      'complete' => $complete,
      'indexed' => $indexed,
      'total' => $total,
    ];
  }
  return $rows;
}