You are here

function search_autocomplete_autocomplete in Search Autocomplete 5

Same name and namespace in other branches
  1. 6.4 search_autocomplete.autocomplete.inc \search_autocomplete_autocomplete()
  2. 6 search_autocomplete.module \search_autocomplete_autocomplete()
  3. 6.2 search_autocomplete.module \search_autocomplete_autocomplete()
  4. 7.4 search_autocomplete.autocomplete.inc \search_autocomplete_autocomplete()
  5. 7.2 search_autocomplete.module \search_autocomplete_autocomplete()

The autocompletion suggestion creater. Rollback function for autocomplete parameter in search_form and block

1 string reference to 'search_autocomplete_autocomplete'
search_autocomplete_menu in ./search_autocomplete.module
Add an administration page for this module at admin/settings/search/search_autocomplete

File

./search_autocomplete.module, line 144
Drupal Module: Search Autocomplete New maintener: Miroslav <www.axiomcafe.fr/contact>

Code

function search_autocomplete_autocomplete($search_string) {
  $matches = array();
  $query = search_parse_query($search_string);
  if ($query === NULL || drupal_strlen($query[1][0]) < variable_get('search_autocomplete_trigger', variable_get('minimum_word_size', 3))) {
    print drupal_to_js($matches);
    exit;
  }
  $string = $query[1][0];
  switch (variable_get('search_autocomplete_method', 1)) {
    case 1:
      $result = db_query_range("SELECT DISTINCT s.word FROM {search_index} s, {node} n WHERE s.type = 'node' AND n.nid = s.sid AND n.status = 1 AND LOWER(s.word) LIKE LOWER('%s%%')", $string, 0, variable_get('search_autocomplete_limit', 15));
      break;
    case 2:
      $result = db_query_range("SELECT DISTINCT i.word FROM {search_index} i, {node} n WHERE i.type = 'node' AND n.nid = i.sid AND n.status = 1 AND LOWER(i.word) LIKE LOWER('%s%%') ORDER BY i.word ASC", $string, 0, variable_get('search_autocomplete_limit', 15));
      break;
    case 3:
      $result = db_query_range("SELECT i.word FROM {search_index} i, {node} n WHERE i.type = 'node' AND n.nid = i.sid AND n.status = 1 AND LOWER(i.word) LIKE LOWER('%s%%') GROUP BY i.word ORDER BY SUM(i.score) DESC", $string, 0, variable_get('search_autocomplete_limit', 15));
      break;
    case 4:
      $result = db_query_range("SELECT i.word FROM {search_index} AS i INNER JOIN {search_total} AS t ON i.word = t.word INNER JOIN {node} AS n ON n.nid = i.sid WHERE i.type = 'node' AND n.status = 1 AND LOWER(i.word) LIKE LOWER('%s%%') GROUP BY i.word ORDER BY SUM(i.score * t.count) DESC", $string, 0, variable_get('search_autocomplete_limit', 15));
      break;
  }
  while ($user = db_fetch_object($result)) {
    $matches[$user->word] = check_plain($user->word);
  }
  print drupal_to_js($matches);
  exit;
}