class Search in Google Search Appliance 8
Defines a search connector to GSA.
Hierarchy
- class \Drupal\google_appliance\Service\Search implements SearchInterface
Expanded class hierarchy of Search
1 file declares its use of Search
- TestSearch.php in tests/
modules/ google_appliance_test/ src/ TestSearch.php
4 string references to 'Search'
- google_appliance.services.yml in ./
google_appliance.services.yml - google_appliance.services.yml
- SearchBlockTest::testSearchBlock in tests/
src/ Functional/ SearchBlockTest.php - Test search block form.
- SearchForm::buildForm in src/
Form/ SearchForm.php - Form constructor.
- SearchPageTest::testSearchPage in tests/
src/ Functional/ SearchPageTest.php - Tests search page.
1 service uses Search
File
- src/
Service/ Search.php, line 17
Namespace
Drupal\google_appliance\ServiceView source
class Search implements SearchInterface {
/**
* Config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* HTTP Client.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* Parser.
*
* @var \Drupal\google_appliance\Service\ParserInterface
*/
protected $parser;
/**
* Constructs a new Search object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* Config factory.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* Module handler.
* @param \GuzzleHttp\ClientInterface $httpClient
* HTTP client.
* @param \Drupal\google_appliance\Service\ParserInterface $parser
* Parser.
*/
public function __construct(ConfigFactoryInterface $configFactory, ModuleHandlerInterface $moduleHandler, ClientInterface $httpClient, ParserInterface $parser) {
$this->configFactory = $configFactory;
$this->moduleHandler = $moduleHandler;
$this->httpClient = $httpClient;
$this->parser = $parser;
}
/**
* Performs search.
*
* @param \Drupal\google_appliance\SearchResults\SearchQuery $query
* Search query.
*
* @return \Drupal\google_appliance\SearchResults\ResultSet
* Search result set.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Search:: |
protected | property | Config factory. | |
Search:: |
protected | property | HTTP Client. | |
Search:: |
protected | property | Module handler. | |
Search:: |
protected | property | Parser. | |
Search:: |
public | function |
Performs search. Overrides SearchInterface:: |
1 |
Search:: |
public | function | Constructs a new Search object. |