You are here

public function SearchApiAlterAddUrl::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. This could for instance be used to implement some sort of access filter for security purposes (e.g., don't index unpublished nodes or comments).

Parameters

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

Overrides SearchApiAlterCallbackInterface::alterItems

File

includes/callback_add_url.inc, line 13
Contains SearchApiAlterAddUrl.

Class

SearchApiAlterAddUrl
Search API data alteration callback that adds an URL field for all items.

Code

public function alterItems(array &$items) {
  foreach ($items as &$item) {
    $url = $this->index
      ->datasource()
      ->getItemUrl($item);
    if (!$url) {
      $item->search_api_url = NULL;
      continue;
    }
    $item->search_api_url = url($url['path'], array(
      'absolute' => TRUE,
    ) + $url['options']);
  }
}