diff --git a/config/vufind/combined.ini b/config/vufind/combined.ini index 68dc1ac5e5b3035d8668c560c68010f7f8c9bd9e..1e1f124502290c4bf749e397874936a36e06bb16 100644 --- a/config/vufind/combined.ini +++ b/config/vufind/combined.ini @@ -16,6 +16,12 @@ ; limit = The maximum number of search results to show in this column; note ; that this must be a legal limit value for the chosen search backend. ; (may sometimes require config changes -- e.g. searches.ini, Summon.ini). +; include_recommendations = If set to true, standard 'top' recommendations will be +; displayed at the top of the column. If set to an array +; of recommendation settings (as per searches.ini), the +; specified recommendations will be loaded into the top +; area of the column. If set to false, recommendations +; will be suppressed (default). ; ; All display text is subject to translation and may be added to the language ; .ini files. diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php index b1dfb71f350011c11d381381ca566108bceab28a..955150fe9bb19ddbc9da957578624f202051141c 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php +++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php @@ -231,6 +231,18 @@ class AbstractSearch extends AbstractBase } $rManager = $this->getServiceLocator()->get('VuFind\RecommendPluginManager'); + + // Special case: override recommend settings through parameter (used by + // combined search) + if ($override = $this->params()->fromQuery('recommendOverride')) { + return function ($runner, $p, $searchId) use ($rManager, $override) { + $listener = new RecommendListener($rManager, $searchId); + $listener->setConfig($override); + $listener->attach($runner->getEventManager()->getSharedManager()); + }; + } + + // Standard case: retrieve recommend settings from params object: return function ($runner, $params, $searchId) use ($rManager, $activeRecs) { $listener = new RecommendListener($rManager, $searchId); $config = []; diff --git a/module/VuFind/src/VuFind/Controller/CombinedController.php b/module/VuFind/src/VuFind/Controller/CombinedController.php index dd0fa333d0b68ff2075b26e677a7449ccd7ef43f..fb319fda7d44793965d446cbdd9be690498c2f1c 100644 --- a/module/VuFind/src/VuFind/Controller/CombinedController.php +++ b/module/VuFind/src/VuFind/Controller/CombinedController.php @@ -256,8 +256,22 @@ class CombinedController extends AbstractSearch $query = $this->getRequest()->getQuery(); $query->limit = isset($settings['limit']) ? $settings['limit'] : null; - // Disable top/side recommendations but leave noresults active: - $query->noRecommend = 'top,side'; + // Reset override to avoid bleed-over from one section to the next! + $query->recommendOverride = false; + + // Always leave noresults active (useful for 0-hit searches) and + // side inactive (no room to display) but display or hide top based + // on include_recommendations setting. + if (isset($settings['include_recommendations']) + && $settings['include_recommendations'] + ) { + $query->noRecommend = 'side'; + if (is_array($settings['include_recommendations'])) { + $query->recommendOverride + = ['top' => $settings['include_recommendations']]; + } + } else { + $query->noRecommend = 'top,side'; + } } } - diff --git a/themes/blueprint/templates/combined/results-list.phtml b/themes/blueprint/templates/combined/results-list.phtml index f2e3a9409e0aee79ce2030a3509f1bb3eead64e3..1dff16015e19b962a16d1cf51aa5a5c6feaada7a 100644 --- a/themes/blueprint/templates/combined/results-list.phtml +++ b/themes/blueprint/templates/combined/results-list.phtml @@ -25,6 +25,9 @@ <div class="resulthead"> <div class="floatleft"> <? if ($recordTotal > 0): ?> + <? foreach (($top = $results->getRecommendations('top')) as $current): ?> + <?=$this->recommend($current)?> + <? endforeach; ?> <?=$this->transEsc("Showing")?> <strong><?=$this->localizedNumber($results->getStartRecord())?></strong> - <strong><?=$this->localizedNumber($results->getEndRecord())?></strong> <? if (!isset($view->skipTotalCount)): ?> diff --git a/themes/bootstrap3/templates/combined/results-list.phtml b/themes/bootstrap3/templates/combined/results-list.phtml index f0ced1b2dd941461f1e84026235cebbb545903c1..abbda2156e42494e83f0c652fffb070c5efcea79 100644 --- a/themes/bootstrap3/templates/combined/results-list.phtml +++ b/themes/bootstrap3/templates/combined/results-list.phtml @@ -25,6 +25,9 @@ <div class="clearfix"> <div class="pull-left help-block"> <? if ($recordTotal > 0): ?> + <? foreach (($top = $results->getRecommendations('top')) as $current): ?> + <?=$this->recommend($current)?> + <? endforeach; ?> <?=$this->transEsc("Showing")?> <strong><?=$this->localizedNumber($results->getStartRecord())?></strong> - <strong><?=$this->localizedNumber($results->getEndRecord())?></strong> <? if (!isset($view->skipTotalCount)): ?>