8471158160
One of the ideas behind authority records is that users who search for one term should have related terms (according to the authority file) suggested to them. At the moment, Koha doesn't do that. Adding an authority searching step to regular searches and displaying any suggestions in a "Did you mean" bar at the top of the results would be very useful. This commit adds a Koha::SuggestionEngine class which is in charge of getting suggestions from individual suggestion engine plugins, which much be in the Koha::SuggestionEngine::Plugin::* namespace, and extend Koha::SuggestionEngine::Base. Suggestions are loaded asynchronously using AJAX, and a link to a page with suggestions is provided for users with Javascript turned off. The AuthorityFile suggestion engine plugin looks up the specified search terms in the authority file and then suggests searches for records using matching authorities. Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> Rebased 2 August 2012 and incorporated QA feedback Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> Test plan: - Verified database update added system preference correctly, pref defaults to OFF - Verified search results and detail pages in OPAC and staff still worked the same as before * for no results * with results - Activated system preference and tested various searches * Searches from simple search * Searches from advanced search * Search links in records - Deactivated Javascript - verified fallback works correctly Notes: - Suggested terms can include autorities with no linked records. - When combining more than one search option using advanced search this results in "no suggestions" more often. Feature works best from simple search. Overall great feature making use of authorities in a user friendly way! Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> Rebased on latest master 2012-09-10 Signed-off-by: wajasu <matted-34813@mypacks.net>
43 lines
1.4 KiB
Perl
Executable file
43 lines
1.4 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
#
|
|
# This Koha test module uses Test::MockModule to get around the need for known
|
|
# contents in the authority file by returning a single known authority record
|
|
# for every call to SearchAuthorities
|
|
|
|
use strict;
|
|
use warnings;
|
|
use File::Spec;
|
|
use MARC::Record;
|
|
|
|
use Test::More;
|
|
use Test::MockModule;
|
|
|
|
BEGIN {
|
|
use_ok('Koha::SuggestionEngine');
|
|
}
|
|
|
|
my $module = new Test::MockModule('C4::AuthoritiesMarc');
|
|
$module->mock('SearchAuthorities', sub {
|
|
return [ { 'authid' => '1234',
|
|
'reported_tag' => undef,
|
|
'even' => 0,
|
|
'summary' => {
|
|
'authorized' => [ 'Cooking' ],
|
|
'otherscript' => [],
|
|
'seefrom' => [ 'Cookery' ],
|
|
'notes' => [ 'Your quintessential poor heading selection' ],
|
|
'seealso' => []
|
|
},
|
|
'used' => 1,
|
|
'authtype' => 'Topical Term'
|
|
} ], 1
|
|
});
|
|
|
|
my $suggestor = Koha::SuggestionEngine->new( { plugins => ( 'AuthorityFile' ) } );
|
|
is(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
|
|
|
|
my $result = $suggestor->get_suggestions({search => 'Cookery'});
|
|
|
|
is_deeply($result, [ { 'search' => 'an=1234', 'relevance' => 1, 'label' => 'Cooking' } ], "Suggested correct alternative to 'Cookery'");
|
|
|
|
done_testing();
|