diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php index f042b85b3e0..0a9cda48f39 100644 --- a/module/VuFind/src/VuFind/Search/Base/Results.php +++ b/module/VuFind/src/VuFind/Search/Base/Results.php @@ -512,6 +512,9 @@ public function getNotificationFrequency(): int public function updateSaveStatus($row) { $this->searchId = $row->getId(); + foreach ($this->results as $driver) { + $driver->setExtraDetail('searchId', $this->searchId); + } $this->savedSearch = $row->getSaved(); $this->notificationFrequency = $this->savedSearch ? $row->getNotificationFrequency() : 0; } diff --git a/module/VuFind/src/VuFind/Search/Memory.php b/module/VuFind/src/VuFind/Search/Memory.php index 2650c171a78..e577849be46 100644 --- a/module/VuFind/src/VuFind/Search/Memory.php +++ b/module/VuFind/src/VuFind/Search/Memory.php @@ -258,7 +258,7 @@ public function getLastSearch(): ?\VuFind\Search\Base\Results * * @return ?\VuFind\Search\Base\Results */ - protected function getSearchById(int $id): ?\VuFind\Search\Base\Results + public function getSearchById(int $id): ?\VuFind\Search\Base\Results { if (!array_key_exists($id, $this->searchCache)) { $search = $this->searchService->getSearchByIdAndOwner($id, $this->sessionId, null); diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Record.php b/module/VuFind/src/VuFind/View/Helper/Root/Record.php index 7df038aecc8..a014425ba38 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Record.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Record.php @@ -38,6 +38,8 @@ use VuFind\Db\Service\DbServiceAwareTrait; use VuFind\Db\Service\UserListServiceInterface; use VuFind\Db\Service\UserResourceServiceInterface; +use VuFind\Search\Memory; +use VuFind\Search\UrlQueryHelper; use VuFind\Tags\TagsService; use function get_class; @@ -72,6 +74,13 @@ class Record extends \Laminas\View\Helper\AbstractHelper implements DbServiceAwa */ protected $coverRouter = null; + /** + * Search memory + * + * @var Memory + */ + protected $searchMemory = null; + /** * Record driver * @@ -102,6 +111,18 @@ public function setCoverRouter($router) $this->coverRouter = $router; } + /** + * Inject the search memory + * + * @param Memory $memory Search memory + * + * @return void + */ + public function setSearchMemory(Memory $memory): void + { + $this->searchMemory = $memory; + } + /** * Render a template within a record driver folder. * @@ -460,13 +481,30 @@ public function getLink($type, $lookfor) $prepend = (!str_contains($link, '?')) ? '?' : '&'; - $link .= $this->getView()->plugin('searchTabs') - ->getCurrentHiddenFilterParams( - $this->driver->getSearchBackendIdentifier(), - false, - $prepend - ); - return $link; + $hiddenFilters = null; + // Try to get hidden filters for the current search: + if ($this->searchMemory) { + $searchId = $this->driver->getExtraDetail('searchId') + ?? $this->getView()->plugin('searchMemory')->getLastSearchId(); + if ($searchId && ($search = $this->searchMemory->getSearchById($searchId))) { + $filters = UrlQueryHelper::buildQueryString( + [ + 'hiddenFilters' => $search->getParams()->getHiddenFiltersAsQueryParams(), + ] + ); + $hiddenFilters = $filters ? $prepend . $filters : ''; + } + } + // If we couldn't get hidden filters for the current search, use last filters: + if (null === $hiddenFilters) { + $hiddenFilters = $this->getView()->plugin('searchTabs') + ->getCurrentHiddenFilterParams( + $this->driver->getSearchBackendIdentifier(), + false, + $prepend + ); + } + return $link . $hiddenFilters; } /** diff --git a/module/VuFind/src/VuFind/View/Helper/Root/RecordFactory.php b/module/VuFind/src/VuFind/View/Helper/Root/RecordFactory.php index 336dc2ee301..a337b07c3fb 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/RecordFactory.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/RecordFactory.php @@ -72,6 +72,7 @@ public function __invoke( $config = $container->get(\VuFind\Config\PluginManager::class)->get('config'); $helper = new $requestedName($container->get(TagsService::class), $config); $helper->setCoverRouter($container->get(\VuFind\Cover\Router::class)); + $helper->setSearchMemory($container->get(\VuFind\Search\Memory::class)); return $helper; } } diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php index 6d527e88791..ed9f6337641 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php @@ -146,6 +146,47 @@ public static function ajaxCombinationsProvider(): array ]; } + /** + * Test that combined results contain valid author links with appropriate filtering. + * + * @param bool $leftAjax Should left column load via AJAX? + * @param bool $rightAjax Should right column load via AJAX? + * + * @return void + * + * @dataProvider ajaxCombinationsProvider + */ + public function testCombinedSearchResultsAuthorLinks(bool $leftAjax, bool $rightAjax): void + { + $config = $this->getCombinedIniOverrides(); + // Default configuration does not have authors in both columns; switch to a + // different data set that will let us test authors: + $config['Solr:one']['hiddenFilter'] = 'building:author_relators.mrc'; + $config['Solr:one']['ajax'] = $leftAjax; + $config['Solr:two']['ajax'] = $rightAjax; + $this->changeConfigs( + ['combined' => $config], + ['combined'] + ); + $session = $this->getMinkSession(); + $session->visit($this->getVuFindUrl() . '/Combined'); + $page = $session->getPage(); + $this->findCss($page, '#searchForm_lookfor') + ->setValue('id:"0001732009-1" OR id:"theplus+andtheminus-"'); + $this->clickCss($page, '.btn.btn-primary'); + $this->waitForPageLoad($page); + $this->unFindCss($page, '.fa-spinner.icon--spin'); + // The author link in each column should have an appropriate hidden filter applied: + $this->assertStringContainsString( + 'hiddenFilters%5B%5D=building%3A%22author_relators.mrc%22', + $this->findCss($page, '#combined_Solr____one .result-author')->getAttribute('href') + ); + $this->assertStringContainsString( + 'hiddenFilters%5B%5D=building%3A%22weird_ids.mrc%22', + $this->findCss($page, '#combined_Solr____two .result-author')->getAttribute('href') + ); + } + /** * Test that combined results work in AJAX mode. *