You are here

public function SearchApiAlterNodeStatus::alterItems in Search API 7

Alter items before indexing.

Items which are removed from the array won't be indexed, but will be marked as clean for future indexing.

Parameters

array $items: An array of items to be altered, keyed by item IDs.

Overrides SearchApiAlterCallbackInterface::alterItems

File

includes/callback_node_status.inc, line 40
Contains the SearchApiAlterNodeStatus class.

Class

SearchApiAlterNodeStatus
Exclude unpublished nodes from node indexes.

Code

public function alterItems(array &$items) {
  $multi_types = $this
    ->isMultiEntityIndex($this->index);
  foreach ($items as $id => $item) {
    $node = $item;
    if ($multi_types) {
      if ($item->item_type !== 'node') {
        continue;
      }
      $node = $item->node;
    }
    if (empty($node->status)) {
      unset($items[$id]);
    }
  }
}