Skip to content

Commit

Permalink
Add support for advanced search with Blender.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Sep 4, 2023
1 parent b564d95 commit fe4b7b1
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 36 deletions.
15 changes: 14 additions & 1 deletion config/vufind/Blender.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,26 @@ retain_filters_by_default = true
; With Blender it is recommended to keep this as low as possible.
result_limit = 400

; This section controls the search handler options displayed in blended mode.
; This section shows which search types will display in the basic search box.
; The name of each setting below corresponds with a Search/Fields mapping in
; BlenderMappings.yaml.
[Basic_Searches]
AllFields = "All Fields"
Title = Title
Author = Author
Subject = Subject

; This section defines which search options will be included on the advanced
; search screen.
; The name of each setting below corresponds with a Search/Fields mapping in
; BlenderMappings.yaml. If this section is not defined, Basic_Searches is used
; instead.
[Advanced_Searches]
AllFields = adv_search_all
Title = adv_search_title
Author = adv_search_author
Subject = adv_search_subject

[Sorting]
relevance = sort_relevance
year = sort_year
Expand Down
18 changes: 16 additions & 2 deletions module/VuFind/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@
],
],
],
'legacy-blender-results' => [
'type' => 'Laminas\Router\Http\Literal',
'options' => [
'route' => '/Search/Blended',
'defaults' => [
'controller' => 'Blender',
'action' => 'Results',
],
],
],
'legacy-bookcover' => [
'type' => 'Laminas\Router\Http\Literal',
'options' => [
Expand Down Expand Up @@ -139,6 +149,7 @@
'VuFind\Controller\AuthorController' => 'VuFind\Controller\AbstractBaseFactory',
'VuFind\Controller\AuthorityController' => 'VuFind\Controller\AbstractBaseFactory',
'VuFind\Controller\AuthorityRecordController' => 'VuFind\Controller\AbstractBaseFactory',
'VuFind\Controller\BlenderController' => 'VuFind\Controller\AbstractBaseFactory',
'VuFind\Controller\BrowseController' => 'VuFind\Controller\AbstractBaseWithConfigFactory',
'VuFind\Controller\BrowZineController' => 'VuFind\Controller\AbstractBaseFactory',
'VuFind\Controller\CartController' => 'VuFind\Controller\CartControllerFactory',
Expand Down Expand Up @@ -210,6 +221,8 @@
'authority' => 'VuFind\Controller\AuthorityController',
'AuthorityRecord' => 'VuFind\Controller\AuthorityRecordController',
'authorityrecord' => 'VuFind\Controller\AuthorityRecordController',
'Blender' => 'VuFind\Controller\BlenderController',
'blender' => 'VuFind\Controller\BlenderController',
'Browse' => 'VuFind\Controller\BrowseController',
'browse' => 'VuFind\Controller\BrowseController',
'BrowZine' => 'VuFind\Controller\BrowZineController',
Expand Down Expand Up @@ -712,6 +725,7 @@
$staticRoutes = [
'Alphabrowse/Home', 'Author/FacetList', 'Author/Home', 'Author/Search',
'Authority/FacetList', 'Authority/Home', 'Authority/Search',
'Blender/Advanced', 'Blender/Home', 'Blender/Results',
'Browse/Author', 'Browse/Dewey', 'Browse/Era', 'Browse/Genre', 'Browse/Home',
'Browse/LCC', 'Browse/Region', 'Browse/Tag', 'Browse/Topic', 'Cart/doExport',
'BrowZine/Home', 'BrowZine/Search',
Expand Down Expand Up @@ -753,8 +767,8 @@
'Primo/Advanced', 'Primo/Home', 'Primo/Search',
'QRCode/Show', 'QRCode/Unavailable', 'Records/Home',
'Relais/Login', 'Relais/Request',
'Search/Advanced', 'Search/Blended', 'Search/CollectionFacetList',
'Search/EditMemory', 'Search/Email',
'Search/Advanced',
'Search/CollectionFacetList', 'Search/EditMemory', 'Search/Email',
'Search/FacetList', 'Search/History', 'Search/Home', 'Search/NewItem',
'Search/OpenSearch', 'Search/Reserves', 'Search/ReservesFacetList',
'Search/Results', 'Search/Suggest', 'Search/Versions',
Expand Down
68 changes: 68 additions & 0 deletions module/VuFind/src/VuFind/Controller/BlenderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* Blended Search Controller
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2023.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Controller
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/

namespace VuFind\Controller;

use Laminas\ServiceManager\ServiceLocatorInterface;

/**
* Blended Search Controller
*
* @category VuFind
* @package Controller
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
class BlenderController extends AbstractSearch
{
/**
* Constructor
*
* @param ServiceLocatorInterface $sm Service locator
*/
public function __construct(ServiceLocatorInterface $sm)
{
$this->searchClassId = 'Blender';
parent::__construct($sm);
}

/**
* Is the result scroller active?
*
* @return bool
*/
protected function resultScrollerActive()
{
$config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class)
->get('config');
return isset($config->Record->next_prev_navigation)
&& $config->Record->next_prev_navigation;
}
}
19 changes: 0 additions & 19 deletions module/VuFind/src/VuFind/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,6 @@
*/
class SearchController extends AbstractSolrSearch
{
/**
* Blended search action.
*
* @return mixed
*/
public function blendedAction()
{
$saveId = $this->searchClassId;
try {
$this->searchClassId = 'Blender';
$view = $this->resultsAction();
} catch (\Exception $e) {
$this->searchClassId = $saveId;
throw $e;
}
$this->searchClassId = $saveId;
return $view;
}

/**
* Show facet list for Solr-driven collections.
*
Expand Down
9 changes: 7 additions & 2 deletions module/VuFind/src/VuFind/Search/Blender/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public function __construct(\VuFind\Config\PluginManager $configLoader)
parent::__construct($configLoader);
// Make sure first-last navigation is never enabled since we cannot support:
$this->firstlastNavigation = false;

// Use basic handlers also as default advanced handlers:
if ($this->basicHandlers && !$this->advancedHandlers) {
$this->advancedHandlers = $this->basicHandlers;
}
}

/**
Expand All @@ -69,7 +74,7 @@ public function __construct(\VuFind\Config\PluginManager $configLoader)
*/
public function getSearchAction()
{
return 'search-blended';
return 'blender-results';
}

/**
Expand All @@ -80,7 +85,7 @@ public function getSearchAction()
*/
public function getAdvancedSearchAction()
{
return false;
return 'blender-advanced';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function testOptions(): void
{
$configMgr = $this->createMock(\VuFind\Config\PluginManager::class);
$options = new Options($configMgr);
$this->assertEquals('search-blended', $options->getSearchAction());
$this->assertFalse($options->getAdvancedSearchAction());
$this->assertEquals('blender-results', $options->getSearchAction());
$this->assertEquals('blender-advanced', $options->getAdvancedSearchAction());
$this->assertFalse($options->getFacetListAction());
}
}
2 changes: 1 addition & 1 deletion themes/bootprint3/css/compiled.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/bootstrap3/css/compiled.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions themes/bootstrap3/less/bootstrap.less
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,10 @@ div.holding-notes {
background: transparent;
}
}

/* --- Help menu --- */
.HelpMenu {
list-style-type: none;
margin-bottom: 1rem;
padding: 0;
}
7 changes: 7 additions & 0 deletions themes/bootstrap3/scss/bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,10 @@ div.holding-notes {
background: transparent;
}
}

/* --- Help menu --- */
.HelpMenu {
list-style-type: none;
margin-bottom: 1rem;
padding: 0;
}
50 changes: 50 additions & 0 deletions themes/bootstrap3/templates/blender/advanced.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
// Load the Blender-specific advanced search and inject it into the
// standard advanced search layout:
$this->buildPageOverride = '/search/advanced/build_page_blender.phtml';

ob_start();
?>
<div id="new_group_template">
<div class="adv-group adv-group__blender">
<input type="hidden" name="join" value="AND">
<input type="hidden" name="bool0[]" value="AND">
<label class="adv-group-label"><?=$this->transEsc('adv_search_label')?>:</label>
<?php for ($search = 0; $search < 3; $search++): ?>
<?php if ($search === 0): ?>
<div id="new_search_template">
<?php endif; ?>
<div class="adv-search">
<input id="search_lookfor0_<?=$search ?>" name="lookfor0[]" class="adv-term-input form-control" type="text" value="" aria-label="<?=$this->transEscAttr('search_terms')?>">
<select id="search_type0_<?=$search ?>" name="type0[]" class="adv-term-type form-control" aria-label="<?=$this->transEscAttr('Search type')?>">
<?php foreach ($this->options->getAdvancedHandlers() as $searchVal => $searchDesc): ?>
<option value="<?=$this->escapeHtml($searchVal)?>"><?=$this->transEsc($searchDesc)?></option>
<?php endforeach; ?>
</select>
<a href="#" class="adv-term-remove">
<?=$this->icon('ui-remove') ?>
<span class="sr-only"><?=$this->transEsc('remove') ?></span>
</a>
</div>
<?php if ($search === 0): ?>
</div>
<?php endif; ?>
<?php endfor; ?>
<span class="search_place_holder"></span>
<div>
<a href="#" class="add_search_link hidden icon-link">
<?=$this->icon('ui-add', 'search_place_holder icon-link__icon hidden') ?>
<span class="icon-link__label"><?=$this->transEsc('add_search')?></span>
</a>
</div>
</div>
</div>
<?php
$this->formOverride = ob_get_contents();
ob_end_clean();

$params = (array)$this->vars() + [
'helpTopics' => ['blender_advsearch' => 'Help with Advanced Search', 'blender' => 'Help with Search Operators'],
];
echo $this->render('search/advanced/layout.phtml', $params);
?>
1 change: 1 addition & 0 deletions themes/bootstrap3/templates/blender/home.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?=$this->render('search/home.phtml');
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
$(document).ready(function() {
// Switch and prepare for JS mode
$('#groupPlaceHolder').addClass('hidden');
$('#new_search_template').addClass('hidden').detach().appendTo('[role="main"]');
$('#new_search_template').find('.adv-search').removeAttr('id');
$('#new_search_template').find('input').removeAttr('value');
$('#new_search_template').find('option').removeAttr('selected');
$('#new_group_template').addClass('hidden').detach().appendTo('[role="main"]');
$('#new_group_template .adv-search').remove();
$('#advSearchForm .no-js').remove();
$('#groupJoin').remove();
// Build page
<?php if (isset($this->searchDetails) && is_object($this->searchDetails)): ?>
<?php foreach ($this->searchDetails->getQueries() as $searchGroup): ?>
<?php $i = 0; ?>
<?php foreach ($searchGroup->getQueries() as $search): ?>
<?php if (++$i == 1): ?>
var new_group = addGroup(
'<?=addslashes($search->getString())?>',
'<?=addslashes($search->getHandler())?>'
);
<?php else: ?>
addSearch(new_group, {
term :'<?=addslashes($search->getString())?>',
field:'<?=addslashes($search->getHandler())?>'
});
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
<?php else: ?>
var new_group = addGroup();
addSearch(new_group);
addSearch(new_group);
<?php endif; ?>
});
21 changes: 15 additions & 6 deletions themes/bootstrap3/templates/search/advanced/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
}
}
}

// Set up help topics
$helpTopics = $this->helpTopics ?? [
'advsearch' => 'Help with Advanced Search',
'search' => 'Help with Search Operators',
];
?>

<?=$this->flashmessages()?>
Expand Down Expand Up @@ -207,12 +213,15 @@
</div>
<?php endforeach; ?>
<?php endif; ?>
<h2><?=$this->transEsc('Search Tips')?></h2>
<?php // Data-title attribute is for analytics use. Do not remove. ?>
<div class="facet-group" data-title="<?=$this->escapeHtmlAttr('Search Tips') ?>">
<a class="facet help-link" data-lightbox href="<?=$this->url('help-home')?>?topic=advsearch&amp;_=<?=time() ?>"><?=$this->transEsc('Help with Advanced Search')?></a>
<a class="facet help-link" data-lightbox href="<?=$this->url('help-home')?>?topic=search&amp;_=<?=time() ?>"><?=$this->transEsc('Help with Search Operators')?></a>
</div>
<?php if ($helpTopics): ?>
<h2><?=$this->transEsc('Search Tips')?></h2>
<?php // Data-title attribute is for analytics use. Do not remove. ?>
<div class="facet-group" data-title="<?=$this->escapeHtmlAttr('Search Tips') ?>">
<?php foreach ($helpTopics as $topic => $title): ?>
<a class="facet help-link" data-lightbox href="<?=$this->url('help-home', [], ['query' => ['topic' => $topic, '_' => time()]])?>"><?=$this->transEsc($title)?></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/local_theme_example/css/compiled.css

Large diffs are not rendered by default.

Loading

0 comments on commit fe4b7b1

Please sign in to comment.