You are here

public function Index::indexItems in Search API 8

Indexes a set amount of items.

Will fetch the items to be indexed from the datasources and send them to indexItems(). It will then mark all successfully indexed items as such in the datasource.

Parameters

int $limit: (optional) The maximum number of items to index, or -1 to index all items.

string|null $datasource_id: (optional) If specified, only items of the datasource with that ID are indexed. Otherwise, items from any datasource are indexed.

Return value

int The number of items successfully indexed.

Overrides IndexInterface::indexItems

File

src/Entity/Index.php, line 918

Class

Index
Defines the search index configuration entity.

Namespace

Drupal\search_api\Entity

Code

public function indexItems($limit = '-1', $datasource_id = NULL) {
  if ($this
    ->hasValidTracker() && !$this
    ->isReadOnly()) {
    $tracker = $this
      ->getTrackerInstance();
    $next_set = $tracker
      ->getRemainingItems($limit, $datasource_id);
    if (!$next_set) {
      return 0;
    }
    $items = $this
      ->loadItemsMultiple($next_set);
    if (!$items) {
      return 0;
    }
    try {
      return count($this
        ->indexSpecificItems($items));
    } catch (SearchApiException $e) {
      $variables['%index'] = $this
        ->label();
      $this
        ->logException($e, '%type while trying to index items on index %index: @message in %function (line %line of %file)', $variables);
    }
  }
  return 0;
}