Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : [];
Comment on lines +111 to +112

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified:

Suggested change
$backendConfig = $blenderConfig['Backends']
? $blenderConfig['Backends'] : [];
$backendConfig = $blenderConfig['Backends'] ?? [];

if (!$backendConfig) {
throw new \Exception("No backends enabled in {$this->searchConfig}.ini");
}
Expand Down
48 changes: 11 additions & 37 deletions module/VuFindSearch/src/VuFindSearch/Backend/Blender/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -108,33 +87,28 @@ 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;
$this->config = $config;
$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'] ?? [];
}

/**
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RecordCollection extends \VuFindSearch\Backend\Solr\Response\Json\RecordCo
/**
* Blender configuration.
*
* @var \VuFind\Config\Config
* @var array
*/
protected $config;

Expand Down Expand Up @@ -80,18 +80,16 @@ 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth introducing property promotion here while we're changing types...

* @param array $mappings Mappings configuration
*/
public function __construct($config = null, $mappings = [])
{
$this->config = $config;
$this->mappings = $mappings;
$this->response = static::$template;
$this->initialResultsBackends
= isset($this->config->Blending->initialResults)
? $this->config->Blending->initialResults->toArray()
: [];
= $config['Blending']['initialResults'] ?? [];
}

/**
Expand Down Expand Up @@ -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']
?? '';
}
}
Expand Down Expand Up @@ -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');
Expand All @@ -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%%',
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down