Skip to content

Commit

Permalink
Merge branch 'dev' into holdings-tab-column-widths
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Nov 21, 2023
2 parents a52f7a0 + e6531d7 commit 5a5b04d
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 71 deletions.
4 changes: 4 additions & 0 deletions config/vufind/EDS.ini
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ AU = None
; Requires configuration in LibGuidesAPI.ini.
;useLibGuides = true

; Find database URLs by the LibGuides alternate names field in addition
; to the primary name. Default is true. Requires useLibGuides = true.
;useLibGuidesAlternateNames = false

; Map of database name (matching EDS API 'DbLabel' value) to website URL.
; These databases are added to any retrieved from LibGuides, and override
; the LibGuides URLs if the same name is present here.
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Connection/LibGuides.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getAZ()
}

$result = $this->doGet(
$this->baseUrl . '/az'
$this->baseUrl . '/az?expand=az_props'
);

if (isset($result->errorCode)) {
Expand Down
78 changes: 48 additions & 30 deletions module/VuFind/src/VuFind/Recommend/Databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,57 +74,58 @@ class Databases implements RecommendInterface, \Laminas\Log\LoggerAwareInterface
*
* @var int
*/
protected $limit;

/**
* Name of the configuration file for databases config (minus ".ini").
*
* @var string
*/
protected $databasesConfigFile;
protected $limit = 5;

/**
* The result facet with the list of databases. Each value in the
* array is a level of the facet hierarchy.
*
* @var array
*/
protected $resultFacet;
protected $resultFacet = [];

/**
* For each database facet, the key to the database name.
*
* @var string
*/
protected $resultFacetNameKey;
protected $resultFacetNameKey = 'value';

/**
* Databases listed in configuration file
*
* @var array
*/
protected $configFileDatabases;
protected $configFileDatabases = [];

/**
* Configuration of whether to use the query string as a match point
*
* @var bool
*/
protected $useQuery;
protected $useQuery = true;

/**
* Minimum string length of a query to use as a match point
*
* @var bool
*/
protected $useQueryMinLength;
protected $useQueryMinLength = 3;

/**
* Configuration of whether to use LibGuides as a data source
*
* @var bool
*/
protected $useLibGuides;
protected $useLibGuides = false;

/**
* Configuration of whether to match on the alt_names field in LibGuides
* in addition to the primary name
*
* @var bool
*/
protected $useLibGuidesAlternateNames = true;

/**
* Callable for LibGuides connector
Expand Down Expand Up @@ -159,33 +160,43 @@ public function __construct(
*/
public function setConfig($settings)
{
// Only change settings from current values if they are defined in $settings or .ini

$settings = explode(':', $settings);
$this->limit
= (isset($settings[0]) && is_numeric($settings[0]) && $settings[0] > 0)
? intval($settings[0]) : 5;
? intval($settings[0]) : $this->limit;
$databasesConfigFile = $settings[1] ?? 'EDS';

$databasesConfig = $this->configManager->get($databasesConfigFile)->Databases;
if (!$databasesConfig) {
throw new \Exception("Databases config file $databasesConfigFile must have section 'Databases'.");
}
$configUrls = isset($databasesConfig->url) ? $databasesConfig->url->toArray() : [];
$this->configFileDatabases = array_map(function ($url) {
return ['url' => $url];
}, $configUrls);

$this->resultFacet = isset($databasesConfig->resultFacet)
? $databasesConfig->resultFacet->toArray() : [];
$this->resultFacetNameKey = $databasesConfig->resultFacetNameKey ?? 'value';

$this->useQuery = $databasesConfig->useQuery ?? true;
$this->useQueryMinLength = $databasesConfig->useQueryMinLength ?? 3;

$this->useLibGuides = $databasesConfig->useLibGuides ?? false;
$this->configFileDatabases = $databasesConfig->url?->toArray()
?? $this->configFileDatabases;
array_walk($this->configFileDatabases, function (&$value, $name) {
$value = [
'name' => $name,
'url' => $value,
];
});

$this->resultFacet = $databasesConfig->resultFacet?->toArray() ?? $this->resultFacet;
$this->resultFacetNameKey = $databasesConfig->resultFacetNameKey
?? $this->resultFacetNameKey;

$this->useQuery = $databasesConfig->useQuery ?? $this->useQuery;
$this->useQueryMinLength = $databasesConfig->useQueryMinLength
?? $this->useQueryMinLength;

$this->useLibGuides = $databasesConfig->useLibGuides ?? $this->useLibGuides;
if ($this->useLibGuides) {
// Cache the data related to profiles for up to 10 minutes:
$libGuidesApiConfig = $this->configManager->get('LibGuidesAPI');
$this->cacheLifetime = intval($libGuidesApiConfig->GetAZ->cache_lifetime ?? 600);

$this->useLibGuidesAlternateNames = $databasesConfig->useLibGuidesAlternateNames
?? $this->useLibGuidesAlternateNames;
}
}

Expand Down Expand Up @@ -247,6 +258,9 @@ public function getResults()
return [];
}
$nameToDatabase = $this->getDatabases();

// Array of url => [name, url]. Key by URL so that the same database (under alternate
// names) is not duplicated.
$databases = [];

// Add databases from search query
Expand All @@ -255,7 +269,7 @@ public function getResults()
if (strlen($query) >= $this->useQueryMinLength) {
foreach ($nameToDatabase as $name => $databaseInfo) {
if (str_contains(strtolower($name), $query)) {
$databases[$name] = $databaseInfo;
$databases[$databaseInfo['url']] = $databaseInfo;
}
if (count($databases) >= $this->limit) {
return $databases;
Expand All @@ -274,7 +288,7 @@ public function getResults()
}
$databaseInfo = $nameToDatabase[$name] ?? null;
if ($databaseInfo) {
$databases[$name] = $databaseInfo;
$databases[$databaseInfo['url']] = $databaseInfo;
}
if (count($databases) >= $this->limit) {
return $databases;
Expand Down Expand Up @@ -316,6 +330,10 @@ protected function getLibGuidesDatabases()
$nameToDatabase = [];
foreach ($databases as $database) {
$nameToDatabase[$database->name] = (array)$database;
// The alt_names field is single-valued free text
if ($this->useLibGuidesAlternateNames && ($database->alt_names ?? false)) {
$nameToDatabase[$database->alt_names] = (array)$database;
}
}

$this->putCachedData('libGuidesAZ-nameToDatabase', $nameToDatabase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function testNormal()

$databases = $module->getResults();
$this->assertCount(3, $databases);
$this->assertArrayHasKey('History DB', $databases);
$this->assertArrayNotHasKey('Art DB', $databases);
$this->assertArrayHasKey('http://thepast.com', $databases);
$this->assertArrayNotHasKey('http://fridakahlo.com', $databases);
}

/**
Expand All @@ -86,7 +86,7 @@ public function testDontUseQuery()

$databases = $module->getResults();
$this->assertCount(2, $databases);
$this->assertArrayNotHasKey('History DB', $databases);
$this->assertArrayNotHasKey('http://thepast.com', $databases);
}

/**
Expand All @@ -102,17 +102,52 @@ public function testUseLibGuides()

$databases = $module->getResults();
$this->assertCount(4, $databases);
$this->assertArrayHasKey('Art DB', $databases);
$this->assertArrayHasKey('http://fridakahlo.com', $databases);
}

/**
* Test using LibGuides with a query that matches an alternate name.
*
* @return void
*/
public function testUseLibGuidesWithAlternateName()
{
$configData = $this->mockConfigData();
$configData['Databases']['useLibGuides'] = true;
$module = $this->buildModuleAndProcessResults($configData, 'Geometry');

$databases = $module->getResults();
$this->assertCount(4, $databases);
$this->assertArrayHasKey('http://primenumbers.com', $databases);
}

/**
* Test using LibGuides with a query that matches an alternate name,
* but that config disabled.
*
* @return void
*/
public function testUseLibGuidesWithAlternateNameDisabled()
{
$configData = $this->mockConfigData();
$configData['Databases']['useLibGuides'] = true;
$configData['Databases']['useLibGuidesAlternateNames'] = false;
$module = $this->buildModuleAndProcessResults($configData, 'Geometry');

$databases = $module->getResults();
$this->assertCount(3, $databases);
$this->assertArrayNotHasKey('http://primenumbers.com', $databases);
}

/**
* Build a Databases module, set config and process results.
*
* @param $configData array A Databases config section
* @param $configData array A Databases config section
* @param $queryString string Query string
*
* @return object
*/
protected function buildModuleAndProcessResults($configData)
protected function buildModuleAndProcessResults($configData, $queryString = 'History')
{
$configManager = $this->createMock(\VuFind\Config\PluginManager::class);
$configManager->expects($this->any())->method('get')
Expand All @@ -137,7 +172,7 @@ protected function buildModuleAndProcessResults($configData)
$module->setConfig($settings);

$facetList = $this->mockFacetList();
$results = $this->mockResults($facetList);
$results = $this->mockResults($facetList, $queryString);
$module->process($results);

return $module;
Expand All @@ -151,7 +186,7 @@ protected function buildModuleAndProcessResults($configData)
*
* @return object
*/
protected function mockResults($facetList, $queryString = 'History')
protected function mockResults($facetList, $queryString)
{
$results = $this->getMockBuilder(\VuFind\Search\EDS\Results::class)
->disableOriginalConstructor()
Expand All @@ -171,30 +206,6 @@ protected function mockResults($facetList, $queryString = 'History')
return $results;
}

/**
* Mock up a standard Databases config section.
*
* @return array
*/
protected function mockConfigData()
{
return [
'Databases' => [
'resultFacet' => [
'ContentProvider',
'list',
],
'resultFacetNameKey' => 'value',
'useQuery' => true,
'url' => [
'Sociology DB' => 'http://people.com',
'Biology DB' => 'http://cells.com',
'History DB' => 'http://thepast.com',
],
],
];
}

/**
* Mock up a results facet list.
*
Expand All @@ -219,6 +230,30 @@ protected function mockFacetList()
];
}

/**
* Mock up a standard Databases config section.
*
* @return array
*/
protected function mockConfigData()
{
return [
'Databases' => [
'resultFacet' => [
'ContentProvider',
'list',
],
'resultFacetNameKey' => 'value',
'useQuery' => true,
'url' => [
'Sociology DB' => 'http://people.com',
'Biology DB' => 'http://cells.com',
'History DB' => 'http://thepast.com',
],
],
];
}

/**
* Mock up LibGuides API databases data.
*
Expand All @@ -229,7 +264,13 @@ protected function mockLibGuidesData()
return [
'db_4' => (object)[
'name' => 'Art DB',
'url' => 'fridakahlo.com',
'url' => 'http://fridakahlo.com',
'alt_names' => '',
],
'db_5' => (object)[
'name' => 'Math DB',
'url' => 'http://primenumbers.com',
'alt_names' => 'Geometry DB',
],
];
}
Expand Down
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.

4 changes: 4 additions & 0 deletions themes/bootstrap3/less/components/search.less
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ body.rtl {
.combined-search-container.grid {
margin-left: 1rem;
margin-right: 1rem;

.combined-list {
overflow-wrap: anywhere;
}
}

.combined-jump-links {
Expand Down
4 changes: 4 additions & 0 deletions themes/bootstrap3/scss/components/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ body.rtl {
.combined-search-container.grid {
margin-left: 1rem;
margin-right: 1rem;

.combined-list {
overflow-wrap: anywhere;
}
}

.combined-jump-links {
Expand Down
4 changes: 2 additions & 2 deletions themes/bootstrap3/templates/Recommend/Databases.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<p><?=$this->transEsc('databases_recommend_intro')?></p>
<?php endif; ?>
<div class="list-group">
<?php foreach ($databases as $name => $database): ?>
<?php foreach ($databases as $database): ?>
<div class="list-group-item">
<span>
<a href="<?=$this->escapeHtmlAttr($this->proxyUrl($database['url']))?>" class="title icon-link" target="_blank">
<?=$this->icon('external-link', 'icon-link__icon') ?>
<span class="icon-link__label"><?=$this->escapeHtml($name)?></span>
<span class="icon-link__label"><?=$this->escapeHtml($database['name'])?></span>
</a>
</span>
</div>
Expand Down
Loading

0 comments on commit 5a5b04d

Please sign in to comment.