You are here

public static function SuggestionStorage::getAutocomplete in Autocomplete Search Suggestions 7

Fetch a set of suggestions.

Parameters

string $ngram: The search string.

int $atoms: The number of atoms.

int $limit: The query limit.

Return value

array An array of suggestions.

1 call to SuggestionStorage::getAutocomplete()
suggestion_autocomplete in ./suggestion.module
AJAX search autocomplete callback.

File

src/SuggestionStorage.php, line 60
CRUD methods for the suggestion module.

Class

SuggestionStorage
Database CRUD.

Code

public static function getAutocomplete($ngram = '', $atoms = 0, $limit = 100) {
  $args = array(
    ':ngram' => $ngram,
    ':atoms' => (int) $atoms,
  );
  $stmt = "\n      SELECT\n        ngram,\n        ngram\n      FROM\n        {suggestion}\n      WHERE\n        ngram LIKE :ngram\n        AND src\n        AND atoms <= :atoms\n      ORDER BY\n        density DESC,\n        ngram ASC,\n        atoms ASC\n    ";
  return db_query_range($stmt, 0, (int) $limit, $args)
    ->fetchAllKeyed();
}