You are here

class TestSearch in Google Search Appliance 8

Defines a test only search implementation.

Hierarchy

Expanded class hierarchy of TestSearch

File

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

Namespace

Drupal\google_appliance_test
View source
class TestSearch extends Search {
  const TOTAL = 100;

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Search::$configFactory protected property Config factory.
Search::$httpClient protected property HTTP Client.
Search::$moduleHandler protected property Module handler.
Search::$parser protected property Parser.
Search::__construct public function Constructs a new Search object.
TestSearch::search public function Performs search. Overrides Search::search
TestSearch::TOTAL constant