diff --git a/module/VuFind/src/VuFind/Search/Factory/BlenderBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/BlenderBackendFactory.php index bd163b34b750..bdca9f5344b2 100644 --- a/module/VuFind/src/VuFind/Search/Factory/BlenderBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/BlenderBackendFactory.php @@ -107,9 +107,9 @@ public function __invoke( ) { $this->container = $container; $this->configManager = $container->get(ConfigManagerInterface::class); - $blenderConfig = $this->configManager->getConfigObject($this->searchConfig); - $backendConfig = $blenderConfig->Backends - ? $blenderConfig->Backends->toArray() : []; + $blenderConfig = $this->configManager->getConfigArray($this->searchConfig); + $backendConfig = $blenderConfig['Backends'] + ? $blenderConfig['Backends'] : []; if (!$backendConfig) { throw new \Exception("No backends enabled in {$this->searchConfig}.ini"); } diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Backend.php b/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Backend.php index 31e43355bf46..0bee9026dbdb 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Backend.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Backend.php @@ -56,13 +56,6 @@ class Backend extends AbstractBackend { use \VuFindSearch\Feature\SearchBackendEventManagerTrait; - /** - * Actual backends. - * - * @var array - */ - protected $backends; - /** * Limit for number of records to blend. * @@ -84,20 +77,6 @@ class Backend extends AbstractBackend */ protected $adaptiveBlockSizes; - /** - * Blender configuration. - * - * @var \VuFind\Config\Config - */ - protected $config; - - /** - * Mappings configuration. - * - * @var array - */ - protected $mappings; - /** * Event manager. * @@ -108,17 +87,17 @@ class Backend extends AbstractBackend /** * Constructor. * - * @param array $backends Actual backends - * @param \VuFind\Config\Config $config Blender configuration - * @param array $mappings Mappings configuration - * @param EventManager $events Event manager + * @param array $backends Actual backends + * @param array $config Blender configuration + * @param array $mappings Mappings configuration + * @param EventManager $events Event manager * * @return void */ public function __construct( - array $backends, - \VuFind\Config\Config $config, - $mappings, + protected array $backends, + protected array $config, + protected array $mappings, EventManager $events ) { $this->backends = $backends; @@ -126,15 +105,10 @@ public function __construct( $this->mappings = $mappings; $this->setEventManager($events); - $boostMax = isset($this->config->Blending->initialResults) - ? count($this->config->Blending->initialResults->toArray()) - : 0; + $boostMax = count($this->config['Blending']['initialResults'] ?? []); $this->blendLimit = max(20, $boostMax); - $this->blockSize = intval($this->config->Blending->blockSize ?? 10); - $this->adaptiveBlockSizes - = isset($this->config->Blending->adaptiveBlockSizes) - ? $this->config->Blending->adaptiveBlockSizes->toArray() - : []; + $this->blockSize = intval($this->config['Blending']['blockSize'] ?? 10); + $this->adaptiveBlockSizes = $this->config['Blending']['adaptiveBlockSizes'] ?? []; } /** @@ -249,7 +223,7 @@ protected function processBackendFailures( } // Log the errors and collect a list to display to the user: $this->logError("Search in $backendId failed: " . (string)$exception); - $failedBackends[] = $this->config->Backends[$backendId]; + $failedBackends[] = $this->config['Backends'][$backendId]; } if ($failedBackends) { $mergedCollection->addError( diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Response/Json/RecordCollection.php b/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Response/Json/RecordCollection.php index 3041df110fb1..725c3acbe436 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Response/Json/RecordCollection.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Blender/Response/Json/RecordCollection.php @@ -52,7 +52,7 @@ class RecordCollection extends \VuFindSearch\Backend\Solr\Response\Json\RecordCo /** * Blender configuration. * - * @var \VuFind\Config\Config + * @var array */ protected $config; @@ -80,8 +80,8 @@ class RecordCollection extends \VuFindSearch\Backend\Solr\Response\Json\RecordCo /** * Constructor. * - * @param \VuFind\Config\Config $config Configuration - * @param array $mappings Mappings configuration + * @param ?array $config Configuration + * @param array $mappings Mappings configuration */ public function __construct($config = null, $mappings = []) { @@ -89,9 +89,7 @@ public function __construct($config = null, $mappings = []) $this->mappings = $mappings; $this->response = static::$template; $this->initialResultsBackends - = isset($this->config->Blending->initialResults) - ? $this->config->Blending->initialResults->toArray() - : []; + = $config['Blending']['initialResults'] ?? []; } /** @@ -199,11 +197,11 @@ public function setSourceIdentifier($identifier) */ public function getFacetDelimiter(string $field): string { - $delimitedFacets = $this->config->Advanced_Settings->delimited_facets ?? []; + $delimitedFacets = $this->config['Advanced_Settings']['delimited_facets'] ?? []; foreach ($delimitedFacets as $current) { $parts = explode('|', $current); if ($parts[0] === $field) { - return $parts[1] ?? $this->config->Advanced_Settings->delimiter + return $parts[1] ?? $this->config['Advanced_Settings']['delimiter'] ?? ''; } } @@ -245,7 +243,7 @@ protected function collectBackendRecords(array $collections): array */ public function add(RecordInterface $record, $checkExisting = true) { - $label = $this->config->Backends[$record->getSearchBackendIdentifier()] + $label = $this->config['Backends'][$record->getSearchBackendIdentifier()] ?? ''; if ($label) { $record->addLabel($label, 'source'); @@ -264,7 +262,7 @@ protected function addErrorsFromBackends(array $collections): void { foreach ($collections as $backendId => $collection) { foreach ($collection->getErrors() as $error) { - $label = $this->config->Backends[$backendId]; + $label = $this->config['Backends'][$backendId] ?? null; if (is_string($error) && $label) { $error = [ 'msg' => '%%error%% -- %%label%%', @@ -446,11 +444,11 @@ protected function getHierarchyParentKeys(string $value): array protected function getBlenderFacetStats(array $collections): array { $delimiter = $this->getFacetDelimiter('blender_backend'); - $orFacets = $this->config->Results_Settings->orFacets ?? ''; + $orFacets = $this->config['Results_Settings']['orFacets'] ?? ''; $orFacetList = array_map('trim', explode(',', $orFacets)); $isOrFacet = '*' === $orFacets || in_array('blender_backend', $orFacetList); $result = []; - foreach ($this->config->Backends as $backendId => $name) { + foreach ($this->config['Backends'] ?? [] as $backendId => $name) { $key = $delimiter ? ($backendId . $delimiter . $name) : $backendId; if (isset($collections[$backendId])) { if ($total = $collections[$backendId]->getTotal()) { diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Blender/BackendTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Blender/BackendTest.php index 4467c2a71dce..84e19ab8136e 100644 --- a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Blender/BackendTest.php +++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Blender/BackendTest.php @@ -618,7 +618,7 @@ public function testSearchLimit(): void $eventManager = new EventManager($this->sharedEventManager); $backend = new Backend( $backends, - new Config(static::$config), + static::$config, $this->mappings, $eventManager ); @@ -1074,7 +1074,7 @@ protected function getBackend( $eventManager = new EventManager($this->sharedEventManager); $backend = new Backend( $backends, - new Config($config ?? static::$config), + $config ?? static::$config, $mappings ?? $this->mappings, $eventManager );