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

EDS results recommendation modules. (#1624)

parent 654a74ba
Branches
Tags
No related merge requests found
......@@ -209,6 +209,12 @@ CallNumber = callnumber-sort
; DPLATerms:[collapsed]
; Display results from the DPLA catalog. Provide a boolean to have the sidebar
; collapsed or open on page load.
; EDSResults:[GET parameter]:[result limit]
; Display EDS search results matching the terms found in the specified
; GET parameter (default = "lookfor"), limited to a specified number of
; matches (default = 5).
; EDSResultsDeferred:[GET parameter]:[result limit]
; Same as EDSResults, but loaded via AJAX.
; EuropeanaResults:[url]:[requestParam]:[limit]:[unwanted data providers]
; Display search results from Europeana.eu API.
; Parameters (all are optional):
......
......@@ -322,6 +322,7 @@ edit_list = "Edit List"
edit_list_fail = "Sorry, you are not permitted to edit this list"
edit_list_success = "List successfully updated."
Edition = "Edition"
EDS Results = "EDS Results"
eds_expander_fulltext = "Also search within the full text of the articles"
eds_expander_relatedsubjects = "Apply equivalent subjects"
eds_expander_thesaurus = "Apply related words"
......@@ -674,6 +675,7 @@ mobile_link = "You appear to be on a mobile device; switch to mobile view?"
Monograph Title = "Monograph Title"
more = "more"
More catalog results = "More catalog results"
More EDS Results = "More EDS Results"
More options = "More options"
More Summon results = "More Summon results"
More Topics = "More Topics"
......
<?php
/**
* EDSResults Recommendations Module
*
* PHP version 7
*
* Copyright (C) Villanova University 2020.
*
* 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 Recommendations
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
*/
namespace VuFind\Recommend;
/**
* EDSResults Recommendations Module
*
* This class provides recommendations by doing a search of EDS.
*
* @category VuFind
* @package Recommendations
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
*/
class EDSResults extends SearchObject
{
/**
* Get the search class ID to use for building search objects.
*
* @return string
*/
protected function getSearchClassId()
{
return 'EDS';
}
}
<?php
/**
* EDSResultsDeferred Recommendations Module
*
* PHP version 7
*
* Copyright (C) Villanova University 2020.
*
* 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 Recommendations
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
*/
namespace VuFind\Recommend;
/**
* EDSResultsDeferred Recommendations Module
*
* This class sets up an AJAX call to trigger a call to the EDSResults module.
*
* @category VuFind
* @package Recommendations
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
*/
class EDSResultsDeferred implements RecommendInterface
{
/**
* Raw configuration parameters
*
* @var string
*/
protected $rawParams;
/**
* Current search query
*
* @var string
*/
protected $lookfor;
/**
* Configuration parameters processed for submission via AJAX
*
* @var string
*/
protected $processedParams;
/**
* Store the configuration of the recommendation module.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings)
{
$this->rawParams = $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 \Laminas\Stdlib\Parameters $request Parameter object representing user
* request.
*
* @return void
*/
public function init($params, $request)
{
// Parse out parameters:
$settings = explode(':', $this->rawParams);
// Make sure all elements of the params array are filled in, even if just
// with a blank string, so we can rebuild the parameters to pass through
// AJAX later on!
for ($i = 0; $i < 2; $i++) {
$settings[$i] = $settings[$i] ?? '';
}
// Map the user-specified query field to 'lookfor' for simplicity:
$this->lookfor
= $request->get(empty($settings[0]) ? 'lookfor' : $settings[0], '');
$settings[0] = 'lookfor';
$this->processedParams = implode(':', $settings);
}
/**
* 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)
{
// No action needed
}
/**
* Get the URL parameters needed to make the AJAX recommendation request.
*
* @return string
*/
public function getUrlParams()
{
return 'mod=EDSResults&params=' . urlencode($this->processedParams)
. '&lookfor=' . urlencode($this->lookfor);
}
}
......@@ -55,6 +55,8 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
'collectionsidefacets' => CollectionSideFacets::class,
'doi' => DOI::class,
'dplaterms' => DPLATerms::class,
'edsresults' => EDSResults::class,
'edsresultsdeferred' => EDSResultsDeferred::class,
'europeanaresults' => EuropeanaResults::class,
'europeanaresultsdeferred' => EuropeanaResultsDeferred::class,
'expandfacets' => ExpandFacets::class,
......@@ -105,6 +107,8 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
Deprecated::class => InvokableFactory::class,
DOI::class => InvokableFactory::class,
DPLATerms::class => DPLATermsFactory::class,
EDSResults::class => InjectSearchRunnerFactory::class,
EDSResultsDeferred::class => InvokableFactory::class,
EuropeanaResults::class => EuropeanaResultsFactory::class,
EuropeanaResultsDeferred::class => InvokableFactory::class,
ExpandFacets::class => ExpandFacetsFactory::class,
......
<?php
/**
* EDSResultsDeferred recommendation module Test Class
*
* PHP version 7
*
* Copyright (C) Villanova University 2020.
*
* 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 Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:testing:unit_tests Wiki
*/
namespace VuFindTest\Recommend;
/**
* EDSResultsDeferred recommendation module Test Class
*
* @category VuFind
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:testing:unit_tests Wiki
*/
class EDSResultsDeferredTest extends \VuFindTest\Unit\RecommendDeferredTestCase
{
/**
* Test standard operation
*
* @return void
*/
public function testStandardOperation()
{
$mod = $this->getRecommend(
'VuFind\Recommend\EDSResultsDeferred', ':3',
new \Laminas\Stdlib\Parameters(['lookfor' => 'foo'])
);
$this->assertEquals(
'mod=EDSResults&params=lookfor%3A3&lookfor=foo',
$mod->getUrlParams()
);
}
}
<?php $searchObject = $this->recommend->getResults(); $results = $searchObject->getResults(); if (!empty($results)): ?>
<h4><?=$this->transEsc('EDS Results')?></h4>
<div class="list-group">
<?php foreach ($results as $driver): ?>
<div class="list-group-item">
<span>
<?php $formats = $driver->getFormats(); $format = $formats[0] ?? ''; ?>
<a href="<?=$this->recordLink()->getUrl($driver)?>" class="title <?=$this->record($driver)->getFormatClass($format)?>">
<?=$this->record($driver)->getTitleHtml()?>
</a>
<?php $summAuthors = $driver->getPrimaryAuthorsWithHighlighting(); if (!empty($summAuthors)): ?>
<span class="small">
<?=$this->transEsc('by')?>
<a href="<?=$this->record($driver)->getLink('author', $this->highlight($summAuthors[0], null, true, false))?>"><?=$this->highlight($summAuthors[0])?></a><?php if (count($summAuthors) > 1): ?>, <?=$this->transEsc('more_authors_abbrev')?><?php endif; ?>
</span>
<?php endif; ?>
</span>
</div>
<?php endforeach; ?>
<a class="list-group-item" href="<?=$this->url($searchObject->getOptions()->getSearchAction()) . $searchObject->getUrlQuery()->setLimit($searchObject->getOptions()->getDefaultLimit())?>"><?=$this->transEsc('More EDS results')?>...</a>
</div>
<?php endif ?>
<?php
// Set up Javascript for use below:
$loadJs = 'var url = VuFind.path + "/AJAX/Recommend?' . $this->recommend->getUrlParams() . '";'
. "\$('#edsResultsDeferredRecommend').load(url);";
?>
<div id="edsResultsDeferredRecommend">
<p><?=$this->transEsc("Loading")?>... <img src="<?=$this->imageLink('ajax_loading.gif')?>" /></p>
<?=$this->inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $loadJs, 'SET')?>
</div>
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