Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend databases based on result facets #3160

Merged
merged 35 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
846c61f
Show side recommendations with combined search
maccabeelevine Oct 2, 2023
8810025
Fix php-cs-fixer
maccabeelevine Oct 2, 2023
030473e
Merge branch 'dev' into combined-side-recommendations
maccabeelevine Oct 3, 2023
c87ca5e
Fix else block style
maccabeelevine Oct 3, 2023
b10ae89
Fix typo
maccabeelevine Oct 3, 2023
ebe1e73
Fix noRecommend logic
maccabeelevine Oct 3, 2023
f5b18ab
Change join to implode
maccabeelevine Oct 3, 2023
e502ff2
Remove code for approach 3, discarded for now.
maccabeelevine Oct 3, 2023
3a3d110
Fix php-cs-fixer
maccabeelevine Oct 3, 2023
0e8750f
Force order of recommendation modules
maccabeelevine Oct 3, 2023
0fdbc46
Use actual recommendation module class name
maccabeelevine Oct 4, 2023
2f6f6d2
Add EDS recommendation module to direct link to DBs
maccabeelevine Oct 5, 2023
cbfb1a0
Merge branch 'dev' into eds-databases
maccabeelevine Oct 11, 2023
5da0e2e
Add optional intro
maccabeelevine Oct 11, 2023
d97133e
Proxy url
maccabeelevine Oct 11, 2023
b8711e6
Open link in external tab
maccabeelevine Oct 11, 2023
51499ea
Fix config loading so caching works
maccabeelevine Oct 11, 2023
21f46bb
Fix typo
maccabeelevine Oct 27, 2023
a6977fe
Pass config manager so other configs would be available
maccabeelevine Oct 27, 2023
ca48db1
Support url configuration in EDS.ini
maccabeelevine Oct 27, 2023
90e36aa
Get database list from facets
maccabeelevine Oct 27, 2023
46333ea
Document module in searches.ini
maccabeelevine Oct 30, 2023
9f88a40
Limit results to configured number
maccabeelevine Oct 30, 2023
6c2d5e0
Generalize to work beyond EDS
maccabeelevine Nov 2, 2023
fdabd12
Reference configuration in EDS.ini
maccabeelevine Nov 2, 2023
1bc8c1b
Fix the same typo done three times!
maccabeelevine Nov 6, 2023
ef71eb6
Add example default_side_recommend to EDS.ini
maccabeelevine Nov 6, 2023
bc3ec16
Simplify reference to Databases config
maccabeelevine Nov 6, 2023
1eac8ec
Fix phpcbf
maccabeelevine Nov 6, 2023
29c3dcf
Fix hierarchy typo
maccabeelevine Nov 8, 2023
f6e36ef
Log errors rather than raising exceptions
maccabeelevine Nov 8, 2023
b1095ad
Fix code styling
maccabeelevine Nov 8, 2023
15e28c7
Fix error if LibGuidesAPI not configured
maccabeelevine Nov 10, 2023
cd1e6b0
Merge branch 'dev' into eds-databases
demiankatz Nov 10, 2023
ee324be
Fix icon link styling.
demiankatz Nov 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions config/vufind/EDS.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ default_view = brief
; sections below.
;default_top_recommend[] = TopFacets:FacetsTop:EDS
default_side_recommend[] = SideFacets:Facets:CheckboxFacets:EDS
;default_side_recommend[] = Databases:5:EDS
;default_noresults_recommend[] = SwitchTab
default_noresults_recommend[] = SwitchType
default_noresults_recommend[] = RemoveFilters
Expand Down Expand Up @@ -340,3 +341,27 @@ AU = None
; documentation on options for different adapters.
; ttl, Time to Live, i.e. cache entry life time in seconds. 300 seconds by default.
;options[ttl] = 300

; This section supports the Databases recommendation module,
; which displays a list of the results' databases, each linking
; to that database's individual website.
[Databases]
demiankatz marked this conversation as resolved.
Show resolved Hide resolved

; Define the facet hierarchy path leading to each database.
; For EDS (the databases are at ContentProvider/list):
;resultFacet[] = 'ContentProvider'
;resultFacet[] = 'list'

; For each database facet, define the key to the database name
; For EDS:
;resultFacetNameKey = 'value'

; Load database URLs from LibGuides. Default is false.
; Requires configuration in LibGuidesAPI.ini.
;useLibGuides = true

; 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.
;url[Expensive Science Database] = https://some.url
;url[Cool Humanities Database] = https://another.url
9 changes: 9 additions & 0 deletions config/vufind/LibGuidesAPI.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ api_base_url = https://lgapi-us.libapps.com/1.2
; Duration (seconds) to cache response data. Default is 600.
;cache_lifetime = 600

; Calls to GET (...)/az endpoint
; Note this is not used for the LibGuidesAZ search
; implementation; see LibGuidesAZ.ini for that.
; This is used where the full list of databases is needed
; by the Databases recommendation module.
[GetAZ]
; Duration (seconds) to cache response data. Default is 600.
;cache_lifetime = 600

; Configuration for LibGuidesProfile recommendation module
[Profile]
; Enable one or more strategies for matching the best profile
Expand Down
4 changes: 4 additions & 0 deletions config/vufind/searches.ini
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ WorkKeys = year
; Display catalog search results matching the terms found in the specified
; GET parameter (default = "lookfor"), limited to a specified number of
; matches (default = 5). This is designed for use with non-catalog modules.
; Databases:[result limit]:[ini name]
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
; Displays a list of the databases referenced in EDS or similar facets, each
; linking to its individual website. The .ini file must contain a [Databases]
; section with the relevant configuration; see example in EDS.ini.
; DPLATerms:[collapsed]
; Display results from the DPLA catalog. Provide a boolean to have the sidebar
; collapsed or open on page load.
Expand Down
2 changes: 2 additions & 0 deletions languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ Created = "Created"
csrf_validation_failed = "The request could not be processed. Please try again."
Data Set = "Data Set"
Database = "Database"
databases = "Search Relevant Databases"
databases_intro = "Search directly in databases for enhanced functionality."
Date = "Date"
Date of birth = "Date of birth"
Date of death = "Date of death"
Expand Down
62 changes: 58 additions & 4 deletions module/VuFind/src/VuFind/Connection/LibGuides.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,57 @@ public function __construct(
* if an error occurs
*/
public function getAccounts()
{
if (!$this->authenticateAndSetHeaders()) {
return null;
}

$result = $this->doGet(
$this->baseUrl . '/accounts?expand=profile,subjects'
);

if (isset($result->errorCode)) {
return null;
}
return $result;
}

/**
* Load all LibGuides AZ databases.
*
* @return object|null A JSON object of all LibGuides databases, or null
* if an error occurs
*/
public function getAZ()
{
if (!$this->authenticateAndSetHeaders()) {
return null;
}

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

if (isset($result->errorCode)) {
return null;
}
return $result;
}

/**
* Authenticate to the LibGuides API and set authentication headers.
*
* @return bool Indicates if authentication succeeded.
*/
protected function authenticateAndSetHeaders()
{
$tokenData = $this->authenticateWithClientCredentials(
$this->baseUrl . '/oauth/token',
$this->clientId,
$this->clientSecret
);
if (!$tokenData) {
return null;
return false;
}

$headers = [];
Expand All @@ -143,10 +186,21 @@ public function getAccounts()
$headers[] = 'User-Agent: ' . $this->userAgent;

$this->client->setHeaders($headers);

return true;
}

/**
* Perform a GET request to the LibGuides API.
*
* @param string $url Full request url
*
* @return object|null A JSON object of the response data, or null if an error occurs
*/
protected function doGet($url)
{
$this->client->setMethod('GET');
$this->client->setUri(
$this->baseUrl . '/accounts?expand=profile,subjects'
);
$this->client->setUri($url);
try {
$response = $this->client->send();
} catch (Exception $ex) {
Expand Down
Loading