You are here

public function TestSearch::search in Google Search Appliance 8

Performs search.

Parameters

\Drupal\google_appliance\SearchResults\SearchQuery $query: Search query.

Return value

\Drupal\google_appliance\SearchResults\ResultSet Search result set.

Overrides Search::search

File

tests/modules/google_appliance_test/src/TestSearch.php, line 20

Class

TestSearch
Defines a test only search implementation.

Namespace

Drupal\google_appliance_test

Code

public function search(SearchQuery $searchQuery) {
  $config = $this->configFactory
    ->get('google_appliance.settings');
  $perPage = $config
    ->get('display_settings.results_per_page');
  $result = new ResultSet();
  $result
    ->setTotal(self::TOTAL)
    ->setLastResult(20);
  foreach (range(1, $perPage) as $item) {
    $result
      ->addResult(new Result('http://example.com', 'http://example.com', sprintf('Result %d', $item), sprintf('this is a snippet from item %d', $item), date('Y-m-d'), 'text/html'));
  }
  if ($searchQuery
    ->getSearchQuery() === 'unicorns') {
    $result
      ->addSynonym(new Synonym('Donkeys', 'donkeys'));
  }
  return $result
    ->setSearchTitle($config
    ->get('display_settings.search_title'))
    ->setQuery($searchQuery)
    ->setResultsPerPage($perPage);
}