You are here

public static function TestsHelper::getAutocompleteSuggestions in Search API Autocomplete 8

Retrieves autocompletion suggestions for some user input.

Parameters

\Drupal\search_api\Backend\BackendInterface $backend: The backend on which this method was originally called.

\Drupal\search_api\Query\QueryInterface $query: A query representing the base search, with all completely entered words in the user input so far as the search keys.

\Drupal\search_api_autocomplete\SearchInterface $search: An object containing details about the search the user is on, and settings for the autocompletion. See the class documentation for details. Especially $search->getOptions() should be checked for settings, like whether to try and estimate result counts for returned suggestions.

string $incomplete_key: The start of another fulltext keyword for the search, which should be completed. Might be empty, in which case all user input up to now was considered completed. Then, additional keywords for the search could be suggested.

string $user_input: The complete user input for the fulltext search keywords so far.

Return value

\Drupal\search_api_autocomplete\Suggestion\SuggestionInterface[] An array of autocomplete suggestions.

See also

\Drupal\search_api_autocomplete\AutocompleteBackendInterface::getAutocompleteSuggestions()

File

src/Tests/TestsHelper.php, line 57

Class

TestsHelper
Contains helper methods for running tests.

Namespace

Drupal\search_api_autocomplete\Tests

Code

public static function getAutocompleteSuggestions(BackendInterface $backend, QueryInterface $query, SearchInterface $search, $incomplete_key, $user_input) {
  $args = array_slice(func_get_args(), 1);
  static::logMethodCall('backend', __FUNCTION__, $args);
  $suggestions = [];
  $factory = new SuggestionFactory($user_input);
  for ($i = 1; $i <= $query
    ->getOption('limit', 10); ++$i) {
    $suggestions[] = $factory
      ->createFromSuggestionSuffix("-backend-{$i}", $i);
  }
  return $suggestions;
}