You are here

public function SearchApiAlterAddUserContent::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_user_content.inc, line 36
Contains SearchApiAlterAddUserContent.

Class

SearchApiAlterAddUserContent
Adds the nodes created by the indexed user for indexing.

Code

public function alterItems(array &$items) {
  $uids = array();
  foreach ($items as $item) {
    $uids[] = $item->uid;
  }
  $sql = 'SELECT nid, uid FROM {node} WHERE uid IN (:uids)';
  $nids = db_query($sql, array(
    ':uids' => $uids,
  ));
  $user_nodes = array();
  foreach ($nids as $row) {
    $user_nodes[$row->uid][] = $row->nid;
  }
  foreach ($items as $item) {
    $item->search_api_user_content = array();
    if (!empty($user_nodes[$item->uid])) {
      $item->search_api_user_content = $user_nodes[$item->uid];
    }
  }
}