Bug 33277: Support custom thesaurus authority with no 040 specified

Signed-off-by: Frank Hansen <frank.hansen@ub.lu.se>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-03-21 17:31:31 +00:00 committed by Tomas Cohen Arazi
parent d73f567366
commit be0241ea69
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 44 additions and 9 deletions

View file

@ -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

View file

@ -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");
};