Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: incorrect author link hidden filter in combined search #3557

3 changes: 3 additions & 0 deletions module/VuFind/src/VuFind/Search/Base/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Search/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
52 changes: 45 additions & 7 deletions module/VuFind/src/VuFind/View/Helper/Root/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading