Bugzilla – Attachment 149838 Details for
Bug 33277
Correctly handle linking subfields with no defined thesaurus
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33277: Support custom thesaurus authority with no 040 specified
Bug-33277-Support-custom-thesaurus-authority-with-.patch (text/plain), 6.09 KB, created by
Frank Hansen
on 2023-04-19 08:10:38 UTC
(
hide
)
Description:
Bug 33277: Support custom thesaurus authority with no 040 specified
Filename:
MIME Type:
Creator:
Frank Hansen
Created:
2023-04-19 08:10:38 UTC
Size:
6.09 KB
patch
obsolete
>From 2129fa478f14bc2266befdcaef1e201c85f6ece4 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 21 Mar 2023 17:31:31 +0000 >Subject: [PATCH] Bug 33277: Support custom thesaurus authority with no 040 > specified > >Signed-off-by: Frank Hansen <frank.hansen@ub.lu.se> >--- > C4/Heading.pm | 17 ++++++++++++++++- > t/db_dependent/Heading.t | 36 ++++++++++++++++++++++++++++-------- > 2 files changed, 44 insertions(+), 9 deletions(-) > >diff --git a/C4/Heading.pm b/C4/Heading.pm >index 8b8ece8aac..3054fc5305 100644 >--- a/C4/Heading.pm >+++ b/C4/Heading.pm >@@ -233,7 +233,22 @@ sub _search { > \@value, $self->{'auth_type'}, > 'AuthidAsc' > ); >- return $searcher->search_auth_compat( $search_query, 0, 20, $skipmetadata ); >+ >+ 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') ) ){ >+ pop @value; >+ push @value, 'z'; >+ $search_query = $builder->build_authorities_query_compat( >+ \@marclist, \@and_or, \@excluding, \@operator, >+ \@value, $self->{'auth_type'}, >+ 'AuthidAsc' >+ ); >+ ( $matched_auths, $total ) = $searcher->search_auth_compat( $search_query, 0, 20, $skipmetadata ); >+ } >+ return ( $matched_auths, $total ); >+ > } > > =head1 INTERNAL FUNCTIONS >diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t >index db7c8ffc14..92d52e1c38 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 => 6; >+ plan tests => 7; > > t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); > t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); >@@ -74,13 +74,13 @@ subtest "_search tests" => sub { > $search->mock('search_auth_compat', sub { > my $self = shift; > my $search_query = shift; >- return $search_query; >+ return ($search_query, 1 ); > }); > > > my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' ); > my $heading = C4::Heading->new_from_field($field); >- my $search_query = $heading->_search( 'match-heading' ); >+ my ($search_query) = $heading->_search( 'match-heading' ); > my $terms = $search_query->{query}->{bool}->{must}; > my $expected_terms = [ > { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, >@@ -90,7 +90,7 @@ subtest "_search tests" => sub { > > $field = MARC::Field->new( '650', ' ', '3', a => 'Uncles', x => 'Fiction' ); > $heading = C4::Heading->new_from_field($field); >- $search_query = $heading->_search( 'match-heading' ); >+ ($search_query) = $heading->_search( 'match-heading' ); > $terms = $search_query->{query}->{bool}->{must}; > $expected_terms = [ > { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, >@@ -100,7 +100,7 @@ subtest "_search tests" => sub { > > $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' ); > $heading = C4::Heading->new_from_field($field); >- $search_query = $heading->_search( 'match-heading' ); >+ ($search_query) = $heading->_search( 'match-heading' ); > $terms = $search_query->{query}->{bool}->{must}; > $expected_terms = [ > { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, >@@ -110,7 +110,7 @@ subtest "_search tests" => sub { > > $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,' ); > $heading = C4::Heading->new_from_field($field); >- $search_query = $heading->_search( 'match-heading' ); >+ ($search_query) = $heading->_search( 'match-heading' ); > $terms = $search_query->{query}->{bool}->{must}; > $expected_terms = [ > { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } }, >@@ -119,7 +119,7 @@ subtest "_search tests" => sub { > > $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' ); > $heading = C4::Heading->new_from_field($field); >- $search_query = $heading->_search( 'match-heading' ); >+ ($search_query) = $heading->_search( 'match-heading' ); > $terms = $search_query->{query}->{bool}->{must}; > $expected_terms = [ > { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } }, >@@ -128,11 +128,31 @@ subtest "_search tests" => sub { > > $field = MARC::Field->new( '100', ' ', '', a => 'Tolkien, J.R.R.,', e => '[author]' ); > $heading = C4::Heading->new_from_field($field); >- $search_query = $heading->_search( 'match-heading' ); >+ ($search_query) = $heading->_search( 'match-heading' ); > $terms = $search_query->{query}->{bool}->{must}; > $expected_terms = [ > { term => { 'match-heading.ci_raw' => 'Tolkien, J.R.R' } }, > ]; > is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field with double punctuation, period+comma "); > >+ $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' ){ >+ return; >+ } >+ return ($search_query, 1); >+ }); >+ >+ # Special case where thesaurus defined in subfield 2 should also match record with no thesaurus >+ $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' ); >+ $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' => 'z' } }, >+ ]; >+ is_deeply( $terms, $expected_terms, "When thesaurus in subfield 2, and nothing is found, we should search again for 008_11 = z"); >+ > }; >-- >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 33277
:
148417
|
148418
|
148419
|
148492
|
148493
|
148494
|
148495
|
148500
|
148527
|
148528
|
148529
|
148530
|
148531
|
148734
|
148735
|
148957
|
149837
|
149838
|
149839
|
149840
|
149841
|
149842
|
150890
|
150891
|
150977
|
150978
|
150979
|
150980
|
150981
|
150982
|
150983