From bf7389d6014eb0bb9a9bfcffe875940177f26a01 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 18 Apr 2023 13:13:12 +0000 Subject: [PATCH] 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 Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- C4/Heading.pm | 7 +++-- .../data/mysql/atomicupdate/bug_33557.pl | 15 ++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/authorities.pref | 7 +++++ t/db_dependent/Heading.t | 30 +++++++++++++++++-- 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_33557.pl diff --git a/C4/Heading.pm b/C4/Heading.pm index ca77c02262..9a56bf9a01 100644 --- a/C4/Heading.pm +++ b/C4/Heading.pm @@ -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', diff --git a/installer/data/mysql/atomicupdate/bug_33557.pl b/installer/data/mysql/atomicupdate/bug_33557.pl new file mode 100755 index 0000000000..81b82898fa --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_33557.pl @@ -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'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index ccedbf901e..d06660ff46 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -343,6 +343,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'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref index a8a5244368..787906e1cc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref @@ -119,3 +119,10 @@ Authorities: 1: Do 0: "Don't" - attempt to automatically link headings when saving records in the cataloging module, obeys LinkerRelink and CatalogModuleRelink 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. diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t index 7858054fda..80ce96b842 100755 --- a/t/db_dependent/Heading.t +++ b/t/db_dependent/Heading.t @@ -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"); + }; -- 2.39.5