You are here

public static function SuggestionStorage::search in Autocomplete Search Suggestions 8

Same name and namespace in other branches
  1. 8.2 src/SuggestionStorage.php \Drupal\suggestion\SuggestionStorage::search()
  2. 3.0.x src/SuggestionStorage.php \Drupal\suggestion\SuggestionStorage::search()

Search suggestions.

Parameters

string $ngram: The requested ngram.

int $start: The starting offset.

int $limit: The query limit.

Return value

array An array of suggestion objects.

1 call to SuggestionStorage::search()
SuggestionSearchForm::buildForm in src/Form/SuggestionSearchForm.php
The suggestion search form.

File

src/SuggestionStorage.php, line 270

Class

SuggestionStorage
Database CRUD.

Namespace

Drupal\suggestion

Code

public static function search($ngram, $start = NULL, $limit = 100) {
  $args = [
    ':ngram' => $ngram,
  ];
  if (is_numeric($start) && intval($limit)) {
    return db_query_range("SELECT * FROM {suggestion} WHERE ngram LIKE :ngram ORDER BY ngram ASC", $start, $limit, $args)
      ->fetchAll();
  }
  return db_query("SELECT * FROM {suggestion} WHERE ngram LIKE :ngram ORDER BY ngram ASC", $args)
    ->fetchAll();
}