public function Search::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 SearchInterface::search
1 method overrides Search::search()
- TestSearch::search in tests/
modules/ google_appliance_test/ src/ TestSearch.php - Performs search.
File
- src/
Service/ Search.php, line 75
Class
- Search
- Defines a search connector to GSA.
Namespace
Drupal\google_appliance\ServiceCode
public function search(SearchQuery $query) {
$config = $this->configFactory
->get('google_appliance.settings');
$resultsPerPage = (int) $config
->get('display_settings.results_per_page');
$params = [
'site' => Html::escape($config
->get('connection_info.collection')),
'oe' => 'utf8',
'ie' => 'utf8',
'getfields' => '*',
'client' => Html::escape($config
->get('connection_info.frontend')),
'start' => $query
->getPage() * $resultsPerPage,
'num' => Html::escape($config
->get('display_settings.results_per_page')),
'filter' => Html::escape($config
->get('query_param.autofilter')),
'q' => $query
->getSearchQuery(),
'output' => 'xml_no_dtd',
'sort' => $query
->getSort(),
'access' => 'p',
];
$this->moduleHandler
->alter('google_appliance_query', $params);
try {
$response = $this->httpClient
->request('GET', $config
->get('connection_info.hostname') . '/search', [
'query' => $params,
]);
$return = $this->parser
->parseResponse((string) $response
->getBody());
} catch (GuzzleException $e) {
$return = (new ResultSet())
->addError($e
->getMessage(), ResultSet::ERROR_HTTP);
}
$this->moduleHandler
->alter('google_appliance_response', $return);
return $return
->setSearchTitle($config
->get('display_settings.search_title'))
->setQuery($query)
->setResultsPerPage($resultsPerPage);
}