You are here

function advanced_help_search_execute in Advanced Help 7

Implements hook_search_execute().

File

./advanced_help.module, line 991
Pluggable system to provide advanced help facilities for Drupal and modules.

Code

function advanced_help_search_execute($keys = NULL) {
  $topics = advanced_help_get_topics();
  $query = db_select('search_index', 'i', array(
    'target' => 'slave',
  ))
    ->extend('SearchQuery')
    ->extend('PagerDefault');
  $query
    ->join('advanced_help_index', 'ahi', 'i.sid = ahi.sid');
  $query
    ->searchExpression($keys, 'help');

  // Only continue if the first pass query matches.
  if (!$query
    ->executeFirstPass()) {
    return array();
  }
  $results = array();
  $find = $query
    ->execute();
  foreach ($find as $item) {
    $sids[] = $item->sid;
  }
  $query = db_select('advanced_help_index', 'ahi');
  $result = $query
    ->fields('ahi')
    ->condition('sid', $sids, 'IN')
    ->execute();
  foreach ($result as $sid) {

    // Guard against removed help topics that are still indexed.
    if (empty($topics[$sid->module][$sid->topic])) {
      continue;
    }
    $info = $topics[$sid->module][$sid->topic];
    $text = advanced_help_view_topic($sid->module, $sid->topic);
    $results[] = array(
      'link' => advanced_help_url("help/{$sid->module}/{$sid->topic}"),
      'title' => $info['title'],
      'snippet' => search_excerpt($keys, $text),
    );
  }
  return $results;
}