You are here

function advanced_help_search in Advanced Help 6

Same name and namespace in other branches
  1. 5 advanced_help.module \advanced_help_search()

Implements hook_search().

File

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

Code

function advanced_help_search($op = 'search', $keys = NULL) {
  switch ($op) {
    case 'name':
      return t('Help');
    case 'reset':
      variable_del('advanced_help_last_cron');
      return;
    case 'search':
      $topics = advanced_help_get_topics();
      $find = do_search($keys, 'help');
      if (!$find) {
        return;
      }
      $results = array();
      $placeholders = implode(', ', array_fill(0, count($find), '%d'));
      foreach ($find as $item) {
        $sids[] = $item->sid;
      }
      $result = db_query("SELECT * FROM {advanced_help_index} WHERE sid IN ({$placeholders})", $sids);
      while ($sid = db_fetch_object($result)) {

        // 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;
  }
}