You are here

function apachesolr_og_apachesolr_process_results in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 contrib/apachesolr_og/apachesolr_og.module \apachesolr_og_apachesolr_process_results()

Implementation of hook_apachesolr_process_results().

File

contrib/apachesolr_og/apachesolr_og.module, line 81
Integrates Organic Group info with Apache Solr search application.

Code

function apachesolr_og_apachesolr_process_results(&$results) {
  $key = _apachesolr_og_gid_key();
  $groups = array();
  foreach ($results as $idx => $r) {
    if (!is_array($r['node']->{$key})) {
      $results[$idx]['node']->{$key} = $r['node']->{$key} ? array(
        $r['node']->{$key},
      ) : array();
    }
    foreach ($results[$idx]['node']->{$key} as $gid) {
      $groups[$gid] = $gid;
    }
  }
  if ($groups) {

    // Copied code from og_node_groups_distinguish() and og_nodeapi().
    $accessible_groups = array();
    $placeholders = db_placeholders($groups);
    $result = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.nid IN (' . $placeholders . ')'), $groups);
    while ($row = db_fetch_object($result)) {
      $accessible_groups[] = $row->nid;
    }
    foreach ($results as $idx => $r) {
      $accessible = array_intersect($results[$idx]['node']->{$key}, $accessible_groups);
      if ($accessible) {
        $results[$idx]['extra'][] = format_plural(count($accessible), '1 group', '@count groups');
      }
    }
  }
}