Bug 33557: Add LinkerConsiderThesaurus system preference
Bug 30280 added the ability to use multiple thesauri for authorities in Koha.
This is a large change, and many libraries use authorities in a ess strict manner.
This patch simply adds a preference, disabled by default, to enable this new feature
To test:
1 - Find or create a record with a 650 heading, second indicator 0 (LOC)
2 - Ensure this links to an authority in your system
3 - Disable AutoCreateAuthorities, enable CatalogModuleRelink
4 - Edit the heading to second indicator 2
5 - Save, the heading does not link
6 - Apply patch, updatedatabase, restart all
7 - Edit and save record again
8 - Heading should now link to the LOC authority, despite different second indicator value for source
Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit bf7389d601
)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
e859b6fed5
commit
9019528b6f
5 changed files with 56 additions and 4 deletions
|
@ -202,6 +202,8 @@ sub _search {
|
|||
my @operator;
|
||||
my @value;
|
||||
|
||||
my $check_thesaurus = C4::Context->preference('LinkerConsiderThesaurus');
|
||||
|
||||
# FIXME: We specify values for @and_or and @excluding
|
||||
# but these fields are not used anywhere and should be removed
|
||||
if ($index) {
|
||||
|
@ -211,7 +213,7 @@ sub _search {
|
|||
push @value, $self->{'search_form'};
|
||||
}
|
||||
|
||||
if ( $thesaurus ) {
|
||||
if ( $check_thesaurus && $thesaurus ) {
|
||||
push @marclist, 'thesaurus';
|
||||
push @and_or, 'and';
|
||||
push @excluding, '';
|
||||
|
@ -240,7 +242,8 @@ sub _search {
|
|||
# Some auth records may not contain the 040$f to specify their source
|
||||
# This is legal, so we do a fallback search
|
||||
if (
|
||||
!$total
|
||||
$check_thesaurus
|
||||
&& !$total
|
||||
&& $thesaurus
|
||||
&& none { $_ eq $thesaurus } (
|
||||
'lcsh', 'lcac', 'mesh', 'nal',
|
||||
|
|
15
installer/data/mysql/atomicupdate/bug_33557.pl
Executable file
15
installer/data/mysql/atomicupdate/bug_33557.pl
Executable file
|
@ -0,0 +1,15 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => "33557",
|
||||
description => "Add a system preference LinkerConsiderThesaurus",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
||||
$dbh->do(q{
|
||||
INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
|
||||
('LinkerConsiderThesaurus','0',NULL,'If ON the authority linker will only search for 6XX authorities from the same source as the heading','YesNo')
|
||||
});
|
||||
say $out "Added new system preference 'LinkerConsiderThesaurus'";
|
||||
},
|
||||
};
|
|
@ -339,6 +339,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
|
|||
('LibraryThingForLibrariesTabbedView','0','','Put LibraryThingForLibraries Content in Tabs.','YesNo'),
|
||||
('LibrisKey', '', 'This key must be obtained at http://api.libris.kb.se/. It is unique for the IP of the server.', NULL, 'Free'),
|
||||
('LibrisURL', 'http://api.libris.kb.se/bibspell/', 'This it the base URL for the Libris spellchecking API.',NULL,'Free'),
|
||||
('LinkerConsiderThesaurus','0',NULL,'If ON the authority linker will only search for 6XX authorities from the same source as the heading','YesNo'),
|
||||
('LinkerKeepStale','0',NULL,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.','YesNo'),
|
||||
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
|
||||
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
|
||||
|
|
|
@ -119,3 +119,10 @@ Authorities:
|
|||
1: Do
|
||||
0: "Don't"
|
||||
- attempt to automatically link headings when saving records in the cataloging module, obeys <a href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=LinkerRelink'>LinkerRelink</a> and <a href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=CatalogModuleRelink'>CatalogModuleRelink</a> for record edits.
|
||||
-
|
||||
- pref: LinkerConsiderThesaurus
|
||||
default: no
|
||||
choices:
|
||||
1: Do
|
||||
0: "Don't"
|
||||
- compare the source for 6XX headings to the thesaurus source for authority records when linking. Enabling this preference may require a reindex, and may generate new authority records if AutoCreateAuthorities is enabled.
|
||||
|
|
|
@ -65,7 +65,7 @@ subtest "UNIMARC tests" => sub {
|
|||
|
||||
subtest "_search tests" => sub {
|
||||
|
||||
plan tests => 8;
|
||||
plan tests => 10;
|
||||
|
||||
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
|
||||
t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch');
|
||||
|
@ -80,6 +80,7 @@ subtest "_search tests" => sub {
|
|||
return ($search_query, 1 );
|
||||
});
|
||||
|
||||
t::lib::Mocks::mock_preference('LinkerConsiderThesaurus', '0');
|
||||
|
||||
my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
|
||||
my $heading = C4::Heading->new_from_field($field);
|
||||
|
@ -87,6 +88,18 @@ subtest "_search tests" => sub {
|
|||
my $terms = $search_query->{query}->{bool}->{must};
|
||||
my $expected_terms = [
|
||||
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
|
||||
];
|
||||
is_deeply( $terms, $expected_terms, "Search formed only using heading content, not thesaurus, when LinkerConsiderThesaurus disabled");
|
||||
|
||||
|
||||
t::lib::Mocks::mock_preference('LinkerConsiderThesaurus', '1');
|
||||
|
||||
$field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
|
||||
$heading = C4::Heading->new_from_field($field);
|
||||
($search_query) = $heading->_search( 'match-heading' );
|
||||
$terms = $search_query->{query}->{bool}->{must};
|
||||
$expected_terms = [
|
||||
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
|
||||
{ term => { 'subject-heading-thesaurus.ci_raw' => 'a' } },
|
||||
];
|
||||
is_deeply( $terms, $expected_terms, "Search formed as expected for a subject with second indicator 0");
|
||||
|
@ -151,7 +164,10 @@ subtest "_search tests" => sub {
|
|||
$search->mock('search_auth_compat', sub {
|
||||
my $self = shift;
|
||||
my $search_query = shift;
|
||||
if( $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'special_sauce' ){
|
||||
if(
|
||||
scalar @{$search_query->{query}->{bool}->{must}} == 2 &&
|
||||
$search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'special_sauce'
|
||||
){
|
||||
return;
|
||||
}
|
||||
return ($search_query, 1);
|
||||
|
@ -168,4 +184,14 @@ subtest "_search tests" => sub {
|
|||
];
|
||||
is_deeply( $terms, $expected_terms, "When thesaurus in subfield 2, and nothing is found, we should search again for notdefined (008_11 = z) ");
|
||||
|
||||
t::lib::Mocks::mock_preference('LinkerConsiderThesaurus', '0');
|
||||
|
||||
$search_query = undef;
|
||||
($search_query) = $heading->_search( 'match-heading' );
|
||||
$terms = $search_query->{query}->{bool}->{must};
|
||||
$expected_terms = [
|
||||
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
|
||||
];
|
||||
is_deeply( $terms, $expected_terms, "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurusDisabled");
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue