Bugzilla – Attachment 149804 Details for
Bug 33557
Add a system preference to disable/enable thesaurus checking during authority linking
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33557: Add LinkerConsiderThesaurus system preference
Bug-33557-Add-LinkerConsiderThesaurus-system-prefe.patch (text/plain), 8.76 KB, created by
Nick Clemens (kidclamp)
on 2023-04-18 13:18:49 UTC
(
hide
)
Description:
Bug 33557: Add LinkerConsiderThesaurus system preference
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-04-18 13:18:49 UTC
Size:
8.76 KB
patch
obsolete
>From d10414d0a7960431d0df811738ceb40711dd5b7a Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >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 >--- > C4/Heading.pm | 6 ++-- > .../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, 55 insertions(+), 4 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_33557.pl > >diff --git a/C4/Heading.pm b/C4/Heading.pm >index b408622038..3ca9091779 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, ''; >@@ -239,7 +241,7 @@ sub _search { > my ( $matched_auths, $total ) = $searcher->search_auth_compat( $search_query, 0, 20, $skipmetadata ); > # Some auth records may not contain the 040$f to specify their source > # This is legal, so we do a fallback search >- if( !$total && $thesaurus && !( grep /$thesaurus/,('lcsh','lcac','mesh','nal','notspecified','cash','rvm','sears','aat') ) ){ >+ if( $check_thesaurus && !$total && $thesaurus && !( grep /$thesaurus/,('lcsh','lcac','mesh','nal','notspecified','cash','rvm','sears','aat') ) ){ > pop @value; > push @value, 'notdefined'; > $search_query = $builder->build_authorities_query_compat( >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 e899c44ba5..f78783722b 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -344,6 +344,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 <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. >diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t >index 7858054fda..58abf3f808 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.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33557
:
149804
|
149830
|
151018