Skip to content
Snippets Groups Projects
Commit b2a35a79 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Allow search handlers to be applied to combined search. (#1392)

- Works by matching human-readable labels.
parent 16d1f732
No related merge requests found
......@@ -42,6 +42,18 @@
; The order of sections in this file will control the display order of search
; results on screen.
; This section controls the search handler options displayed in combined mode.
; The keys and values should be the same. When performing searches, the code will
; attempt to find a search option in each target backend whose description matches
; the key/value pair here. If no match is found, the default handler will be used.
; Combined search handlers are disabled by default, since this matching may not be
; applicable to all backends and may create a confusing user experience.
[Basic_Searches]
;All Fields = "All Fields"
;Title = Title
;Author = Author
;Subject = Subject
; This section controls the behavior of the Combined/Home screen.
[HomePage]
; Content blocks can be selected from the list in searches.ini.
......
......@@ -98,7 +98,10 @@ class CombinedController extends AbstractSearch
= explode('-', $currentOptions->getSearchAction());
$settings = $tabConfig[$sectionId];
$this->adjustQueryForSettings($settings);
$this->adjustQueryForSettings(
$settings,
$currentOptions->getHandlerForLabel($this->params()->fromQuery('type'))
);
$settings['view'] = $this->forwardTo($controller, $action);
// Should we suppress content due to emptiness?
......@@ -157,10 +160,14 @@ class CombinedController extends AbstractSearch
->get('combined')->toArray();
$supportsCart = false;
$supportsCartOptions = [];
// Save the initial type value, since it may get manipulated below:
$initialType = $this->params()->fromQuery('type');
foreach ($this->getTabConfig($config) as $current => $settings) {
list($searchClassId) = explode(':', $current);
$this->adjustQueryForSettings($settings);
$currentOptions = $options->get($searchClassId);
$this->adjustQueryForSettings(
$settings, $currentOptions->getHandlerForLabel($initialType)
);
$supportsCartOptions[] = $currentOptions->supportsCart();
if ($currentOptions->supportsCart()) {
$supportsCart = true;
......@@ -185,6 +192,9 @@ class CombinedController extends AbstractSearch
}
}
// Restore the initial type value to the query to prevent weird behavior:
$this->getRequest()->getQuery()->type = $initialType;
// Run the search to obtain recommendations:
$results->performAndProcessSearch();
......@@ -266,11 +276,12 @@ class CombinedController extends AbstractSearch
/**
* Adjust the query context to reflect the current settings.
*
* @param array $settings Settings
* @param array $settings Settings
* @param string $searchType Override for search handler name
*
* @return void
*/
protected function adjustQueryForSettings($settings)
protected function adjustQueryForSettings($settings, $searchType = null)
{
// Apply limit setting, if any:
$query = $this->getRequest()->getQuery();
......@@ -295,6 +306,9 @@ class CombinedController extends AbstractSearch
// load a record view in the context of combined search.
$query->jumpto = false;
// Override the search type:
$query->type = $searchType;
// 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.
......@@ -319,6 +333,7 @@ class CombinedController extends AbstractSearch
protected function getTabConfig($config)
{
// Strip out non-tab sections of the configuration:
unset($config['Basic_Searches']);
unset($config['HomePage']);
unset($config['Layout']);
unset($config['RecommendationModules']);
......
......@@ -38,6 +38,22 @@ namespace VuFind\Search\Combined;
*/
class Options extends \VuFind\Search\Base\Options
{
/**
* Constructor
*
* @param \VuFind\Config\PluginManager $configLoader Config loader
*/
public function __construct(\VuFind\Config\PluginManager $configLoader)
{
parent::__construct($configLoader);
$searchSettings = $this->configLoader->get('combined');
if (isset($searchSettings->Basic_Searches)) {
foreach ($searchSettings->Basic_Searches as $key => $value) {
$this->basicHandlers[$key] = $value;
}
}
}
/**
* Return the route name for the search results action.
*
......
......@@ -11,9 +11,12 @@
$searchClassIdEncoded = urlencode($searchClassId);
$targetIdHtmlEscaped = $this->escapeHtml('#' . $currentSearch['domId']);
$lookforEncoded = urlencode($lookfor);
$typeEncoded = urlencode($params->getSearchHandler());
$loadJs = <<<JS
$(document).ready(function(){
var url = VuFind.path + '/Combined/Result?id=$searchClassIdEncoded&lookfor=$lookforEncoded';
var url = VuFind.path
+ '/Combined/Result?id=$searchClassIdEncoded&lookfor=$lookforEncoded'
+ '&type=$typeEncoded';
var container = $('$targetIdHtmlEscaped');
VuFind.combinedSearch.init(container, url);
});
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment