Skip to content

Commit

Permalink
[FINNA-2675] Load encapsulated records without source limit
Browse files Browse the repository at this point in the history
Allows encapsulated records to be displayed regardless of the view's sources configuration.
  • Loading branch information
EreMaijala committed Oct 8, 2024
1 parent 3eb6c40 commit dce598a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion module/Finna/src/Finna/Record/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public function loadBatchForSource(
$records = parent::loadBatchForSource(
$ids,
$source,
$tolerateBackendExceptions
$tolerateBackendExceptions,
$params
);

// Check the results for missing records and try to load them with their old IDs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Finna\Record\Loader;
use Finna\RecordDriver\PluginManager;
use VuFind\RecordDriver\AbstractBase;
use VuFindSearch\ParamBag;
use VuFindSearch\Response\RecordInterface;

use function count;
Expand Down Expand Up @@ -142,9 +143,13 @@ public function getEncapsulatedRecord(string $id): ?RecordInterface
$driver instanceof EncapsulatedRecordInterface
&& $needed = $driver->needsRecordLoaded()
) {
$driver->setLoadedRecord(
$this->recordLoader->load($needed['id'], $needed['source'], true)
$loadedRecord = $this->recordLoader->load(
$needed['id'],
$needed['source'],
true,
new ParamBag(['finna.ignore_source_filter' => 1])
);
$driver->setLoadedRecord($loadedRecord);
}
return $driver;
}
Expand Down Expand Up @@ -342,17 +347,22 @@ protected function loadNeededRecords(array $records): void
{
$neededMap = [];
$ids = [];
$params = [];
foreach ($records as $i => $record) {
if (
$record instanceof EncapsulatedRecordInterface
&& $needed = $record->needsRecordLoaded()
) {
$neededMap[$needed['source']][$needed['id']] = $i;
$source = $needed['source'];
$neededMap[$source][$needed['id']] = $i;
$ids[] = $needed;
if (!isset($params[$source])) {
$params[$source] = new ParamBag(['finna.ignore_source_filter' => 1]);
}
}
}
if (!empty($ids)) {
$loadedRecords = $this->recordLoader->loadBatch($ids);
$loadedRecords = $this->recordLoader->loadBatch($ids, params: $params);
foreach ($loadedRecords as $loadedRecord) {
$loadedSource = $loadedRecord->getSourceIdentifier();
$loadedId = $loadedRecord->getUniqueID();
Expand Down
14 changes: 12 additions & 2 deletions module/Finna/src/Finna/Search/Solr/SolrExtensionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,20 @@ public function onSearchPost(EventInterface $event)
*/
protected function addDataSourceFilter(EventInterface $event)
{
$command = $event->getParam('command');
$params = $command->getSearchParameters();
if ($recordSources = $this->getActiveSources($event)) {
$params = $event->getParam('command')->getSearchParameters();
$params->add('fq', static::TERMS_FILTER_PREFIX_SOURCE . implode("\u{001f}", $recordSources));
// Don't add the filter if we're retrieving a batch of records and requested so (e.g. AIPA encapsulated
// records):
$context = $command->getContext();
if (
'retrieve' !== $context
&& ('retrieveBatch' !== $context || !$params->get('finna.ignore_source_filter'))
) {
$params->add('fq', static::TERMS_FILTER_PREFIX_SOURCE . implode("\u{001f}", $recordSources));
}
}
$params->remove('finna.ignore_source_filter');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions module/Finna/src/Finna/View/Helper/Root/RecordFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function __invoke(
$container->get(\VuFind\Form\Form::class),
$container->get(\Finna\Service\UserPreferenceService::class),
function ($options) use ($container) {
$result = clone $container
$result = $container
->get(\VuFind\Search\Results\PluginManager::class)
->get('EncapsulatedRecords');
->get(\Finna\Search\EncapsulatedRecords\Results::class);
$result->getParams()->initFromRequest(new Parameters($options));
return $result;
}
Expand Down

0 comments on commit dce598a

Please sign in to comment.