Skip to content
Permalink
Browse files

Adds suggestion module to change the search tab for nohits

  • Loading branch information...
Oliver Goldschmidt authored and demiankatz committed Jan 28, 2016
1 parent 34cc7a7 commit ffacce62167c15ed2d37801d84a491bc3f1c5d96
@@ -28,6 +28,7 @@ default_view = brief
; sections below.
;default_top_recommend[] = TopFacets:FacetsTop:EDS
default_side_recommend[] = SideFacets:Facets:CheckboxFacets:EDS
;default_noresults_recommend[] = SwitchTab
default_noresults_recommend[] = SwitchType
default_noresults_recommend[] = RemoveFilters

@@ -38,6 +38,7 @@ default_limit = 20
; repeat these lines to load multiple recommendations.
;default_top_recommend[] = TopFacets:FacetsTop:Primo
default_side_recommend[] = SideFacets:Facets:CheckboxFacets:Primo
;default_noresults_recommend[] = SwitchTab
default_noresults_recommend[] = RemoveFilters

; This section is used to set general parameters for URL generation to make a call to
@@ -49,6 +49,7 @@ default_top_recommend[] = SpellingSuggestions
;default_top_recommend[] = SummonTopics
;default_top_recommend[] = TopFacets:FacetsTop:Summon
default_side_recommend[] = SideFacets:Facets:CheckboxFacets:Summon
;default_noresults_recommend[] = SwitchTab
default_noresults_recommend[] = SwitchType
default_noresults_recommend[] = SwitchQuery:Summon
default_noresults_recommend[] = SpellingSuggestions
@@ -4,6 +4,8 @@
; option should be one of the options present in the [Sorting] section below.
default_sort = relevance

;default_noresults_recommend[] = SwitchTab

; This section shows which search types will display in the basic search box at
; the top of WorldCat pages. The name of each setting below corresponds with one
; or more indices defined in the WorldCat API (multiple values are separated by
@@ -55,6 +55,7 @@ default_top_recommend[] = TopFacets:ResultsTop
default_top_recommend[] = SpellingSuggestions
;default_top_recommend[] = VisualFacets:Visual_Settings
default_side_recommend[] = SideFacets:Results:CheckboxFacets
;default_noresults_recommend[] = SwitchTab
default_noresults_recommend[] = SwitchType
default_noresults_recommend[] = SwitchQuery:::fuzzy
default_noresults_recommend[] = SpellingSuggestions
@@ -363,6 +364,9 @@ CallNumber = callnumber-sort
; See the check*() methods in the module's code for a complete list of
; available checks. The $optInMethods property specifies which checks are
; turned off by default.
; SwitchTab
; If multiple tabs are active, suggest that the user try searching in a
; different one.
; SwitchType:[field]:[field description]
; If the current search type is not the same as [field], display a link
; suggesting that the user try switching to [field]. [field description]
@@ -622,6 +622,7 @@ No Tags = "Keine Tags"
no_description = "Keine Beschreibung verfügbar."
no_items_selected = "Sie haben nichts ausgewählt"
nohit_active_filters = "Es wurden Suchfilter/Facetten verwendet. Ohne Filter kann die Ergebnisanzahl möglicherweise erhöht werden."
nohit_change_tab = "Sie haben im Reiter %%activeTab%% gesucht. Möglicherweise finden Sie etwas in einem anderen Reiter:"
nohit_filters = "Verwendete Suchfilter."
nohit_heading = "Keine Ergebnisse!"
nohit_no_filters = "Es wurden keine Filter für diese Suche verwendet."
@@ -624,6 +624,7 @@ No Tags = "No Tags"
no_description = "Description not available."
no_items_selected = "No Items were Selected"
nohit_active_filters = "One or more facet filters have been applied to this search. If you remove filters, you may retrieve more results."
nohit_change_tab = "You have been searching in the "%%activeTab%%" tab. You may find something in one of the other tabs:"
nohit_filters = "Filters currently applied to this search:"
nohit_heading = "No Results!"
nohit_no_filters = "No filters were applied to this search."
@@ -0,0 +1,140 @@
<?php
/**
* SwitchTab Recommendations Module
* Recommends to use another SearchTab
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Recommendations
* @author Oliver Goldschmidt <o.goldschmidt@tuhh.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki
*/
namespace VuFind\Recommend;
/**
* SwitchType Recommendations Module
*
* This class recommends switching to a different search type.
*
* @category VuFind2
* @package Recommendations
* @author Oliver Goldschmidt <o.goldschmidt@tuhh.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki
*/
class SwitchTab implements RecommendInterface
{
/**
* Current tab settings
*
* @var array
*/
protected $tabSelections = null;
/**
* Store the configuration of the recommendation module.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings)
{
}
/**
* Called at the end of the Search Params objects' initFromRequest() method.
* This method is responsible for setting search parameters needed by the
* recommendation module and for reading any existing search parameters that may
* be needed.
*
* @param \VuFind\Search\Base\Params $params Search parameter object
* @param \Zend\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return void
*/
public function init($params, $request)
{
}
/**
* Called after the Search Results object has performed its main search. This
* may be used to extract necessary information from the Search Results object
* or to perform completely unrelated processing.
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return void
*/
public function process($results)
{
}
/**
* Set the tab state based on the current tabConfig.
*
* @param array $tabEnv tabConfig
*
* @return void
*/
protected function setTabSelections($tabEnv)
{
$tabs = [ 'active' => null, 'inactive' => [] ];
foreach ($tabEnv as $tab) {
if ($tab['selected'] === true) {
$tabs['active'] = $tab;
} else {
$tabs['inactive'][] = $tab;
}
}
$this->tabSelections = $tabs;
}
/**
* Get the active tab.
*
* @param array $tabEnv tabConfig
*
* @return string
*/
public function getActiveTab($tabEnv)
{
if ($this->tabSelections === null) {
$this->setTabSelections($tabEnv);
}
return $this->tabSelections['active'];
}
/**
* Get the other (inactive) tabs.
*
* @param array $tabEnv tabConfig
*
* @return array
*/
public function getInactiveTabs($tabEnv)
{
if ($this->tabSelections === null) {
$this->setTabSelections($tabEnv);
}
return $this->tabSelections['inactive'];
}
}
@@ -142,6 +142,22 @@ public function getTabConfig($activeSearchClass, $query, $handler,
return $retVal;
}
/**
* Get the tab configuration
*
* @param \VuFind\Search\Base\Params $params Search parameters
*
* @return array
*/
public function getTabConfigForParams($params)
{
return $this->getTabConfig(
$params->getSearchClassId(), $params->getDisplayQuery(),
$params->getSearchHandler(), $params->getSearchType(),
$params->getHiddenFilters()
);
}
/**
* Get an array of hidden filters
*
@@ -0,0 +1,19 @@
<?
$searchTabs = is_object($this->params)
? $this->searchtabs()->getTabConfigForParams($this->params) : [];
?>
<? if (count($searchTabs) > 0): ?>
<div class="alert alert-info">
<?=$this->transEsc('nohit_change_tab', array('%%activeTab%%' => $this->translate($this->recommend->getActiveTab($searchTabs)['label'])))?>
<ul>
<? $inactiveTabs = $this->recommend->getInactiveTabs($searchTabs); ?>
<? foreach ($inactiveTabs as $tab): ?>
<li>
<? if (!$tab['selected']): ?><a href="<?=$this->escapeHtmlAttr($tab['url'])?>"><? endif; ?>
<?=$this->transEsc($tab['label']); ?>
<? if (!$tab['selected']): ?></a><? endif; ?>
</li>
<? endforeach; ?>
</ul>
</div>
<? endif; ?>
@@ -0,0 +1,19 @@
<?
$searchTabs = is_object($this->params)
? $this->searchtabs()->getTabConfigForParams($this->params) : [];
?>
<? if (count($searchTabs) > 0): ?>
<div class="info">
<?=$this->transEsc('nohit_change_tab', array('%%activeTab%%' => $this->translate($this->recommend->getActiveTab($searchTabs)['label'])))?>
<ul>
<? $inactiveTabs = $this->recommend->getInactiveTabs($searchTabs); ?>
<? foreach ($inactiveTabs as $tab): ?>
<li>
<? if (!$tab['selected']): ?><a rel="external" href="<?=$this->escapeHtmlAttr($tab['url'])?>"><? endif; ?>
<?=$this->transEsc($tab['label']); ?>
<? if (!$tab['selected']): ?></a><? endif; ?>
</li>
<? endforeach; ?>
</ul>
</div>
<? endif; ?>

0 comments on commit ffacce6

Please sign in to comment.
You can’t perform that action at this time.