Skip to content
Snippets Groups Projects
Commit 2c6bf1ca authored by David Maus's avatar David Maus
Browse files

Use new config service in backend factory

* VuFind/Search/Factory/AbstractSolrBackendFactory.php (createService)
  (createConnector): Use new config service.
  (loadSpecs): Use SearchSpecsReader to load specs.
parent dfb4b1e6
No related merge requests found
...@@ -99,9 +99,7 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -99,9 +99,7 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
* Constructor * Constructor
*/ */
public function __construct() public function __construct()
{ {}
$this->config = Reader::getConfig();
}
/** /**
* Create the backend. * Create the backend.
...@@ -113,6 +111,7 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -113,6 +111,7 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
public function createService (ServiceLocatorInterface $serviceLocator) public function createService (ServiceLocatorInterface $serviceLocator)
{ {
$this->serviceLocator = $serviceLocator; $this->serviceLocator = $serviceLocator;
$this->config = $this->serviceLocator->get('VuFind\Config');
if ($this->serviceLocator->has('VuFind\Logger')) { if ($this->serviceLocator->has('VuFind\Logger')) {
$this->logger = $this->serviceLocator->get('VuFind\Logger'); $this->logger = $this->serviceLocator->get('VuFind\Logger');
} }
...@@ -160,20 +159,20 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -160,20 +159,20 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
*/ */
protected function createConnector () protected function createConnector ()
{ {
$searchSettings = Reader::getConfig($this->searchConfig); $config = $this->config->get('config');
$search = $this->config->get('searches');
$url = $this->config->Index->url . '/' . $this->solrCore;
$url = $config->Index->url . '/' . $this->solrCore;
$connector = new Connector($url); $connector = new Connector($url);
$connector->setTimeout( $connector->setTimeout(
isset($this->config->Index->timeout) ? $this->config->Index->timeout : 30 isset($config->Index->timeout) ? $config->Index->timeout : 30
); );
$connector->setQueryDefaults( $connector->setQueryDefaults(
array('wt' => 'json', 'json.nl' => 'arrarr', 'fl' => '*,score') array('wt' => 'json', 'json.nl' => 'arrarr', 'fl' => '*,score')
); );
$hl = !isset($searchSettings->General->highlighting) ? false : $searchSettings->General->highlighting; $hl = !isset($search->General->highlighting) ? false : $search->General->highlighting;
$sn = !isset($searchSettings->General->snippets) ? false : $searchSettings->General->snippets; $sn = !isset($search->General->snippets) ? false : $search->General->snippets;
if ($hl || $sn) { if ($hl || $sn) {
$connector->addQueryAppend('hl', 'true'); $connector->addQueryAppend('hl', 'true');
$connector->addQueryAppend('hl.fl', '*'); $connector->addQueryAppend('hl.fl', '*');
...@@ -182,14 +181,14 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -182,14 +181,14 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
} }
// Hidden filters // Hidden filters
if (isset($searchSettings->HiddenFilters)) { if (isset($search->HiddenFilters)) {
foreach ($searchSettings->HiddenFilters as $field => $value) { foreach ($search->HiddenFilters as $field => $value) {
$connector->addQueryAppend('fq', sprintf('%s:"%s"', $field, $value)); $connector->addQueryAppend('fq', sprintf('%s:"%s"', $field, $value));
} }
} }
// Raw hidden filters // Raw hidden filters
if (isset($searchSettings->RawHiddenFilters)) { if (isset($search->RawHiddenFilters)) {
foreach ($searchSettings->RawHiddenFilters as $filter) { foreach ($search->RawHiddenFilters as $filter) {
$connector->addQueryAppend('fq', $filter); $connector->addQueryAppend('fq', $filter);
} }
} }
...@@ -210,20 +209,7 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -210,20 +209,7 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
*/ */
protected function loadSpecs () protected function loadSpecs ()
{ {
$global = Reader::getBaseConfigPath($this->searchYaml); $specs = $this->serviceLocator->get('VuFind\SearchSpecsReader')->get($this->searchYaml);
$local = Reader::getLocalConfigPath($this->searchYaml);
if ($this->serviceLocator->has('VuFind\CacheManager')) {
$cache = $this->serviceLocator->get('VuFind\CacheManager')->getCache('searchspecs');
$reader = new YamlCacheReader(new YamlReader('Symfony\Component\Yaml\Yaml::parse'), $cache);
} else {
$reader = new YamlReader(new YamlReader('Symfony\Component\Yaml\Yaml::parse'));
}
$specs = $reader->fromFile($global);
if ($local) {
foreach ($reader->fromFile($local) as $key => $value) {
$specs[$key] = $value;
}
}
return $specs; return $specs;
} }
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment