You are here

function activesearch_results in Javascript Tools 5

1 call to activesearch_results()
activesearch_submit in activesearch/activesearch.module

File

activesearch/activesearch.module, line 108

Code

function activesearch_results($keys, $type, $create = TRUE) {

  // We need to call search_data even if we're overriding the results
  // in order to seed the results temporary table.
  $results = $create ? search_data($keys, $type) : array();
  if (($results || !$create) && $type == 'node') {
    switch (variable_get('activesearch_tabs_mode', 'node')) {
      case 'node':

        // If user has entered type information, use it.
        if ($node_types = search_query_extract($keys, 'type')) {
          $node_types = explode(',', $node_types);
        }
        else {
          $node_types = array_filter(variable_get('activesearch_nodes', array()));
          unset($node_types[0]);
        }

        // If neither, use the types of the found items.
        if (!count($node_types)) {
          $result = db_query_range("SELECT DISTINCT(n.type) FROM temp_search_results r INNER JOIN {node} n ON r.sid = n.nid", 0, 10);
          while ($row = db_fetch_array($result)) {
            $node_types[] = $row['type'];
          }
        }
        if (count($node_types)) {
          return theme('activesearch_results', 'node', $keys, $node_types, $results);
        }
        break;
      case 'term':

        // If user has entered type information, use it.
        if ($tids = search_query_extract($keys, 'category')) {
          $tids = explode(',', $tids);
        }
        else {
          $tids = array_filter(variable_get('activesearch_activesearch_terms', array()));
          unset($tids[0]);
        }

        // If neither, use the tids of the found items.
        if (!count($tids)) {
          $result = db_query_range("SELECT DISTINCT(tn.tid) FROM temp_search_results r INNER JOIN {term_node} tn ON r.sid = tn.nid", 0, 10);
          while ($row = db_fetch_array($result)) {
            $tids[] = $row['tid'];
          }
        }
        if (count($tids)) {
          return theme('activesearch_results', 'term', $keys, $tids, $results);
        }
        break;
    }
  }
  return $results ? $results : (form_get_errors() ? theme('status_messages') : t('No matches found.'));
}