From 3cbac6fecd29a16354e31284702f1776ed086913 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 21 Mar 2023 19:34:50 +0000 Subject: [PATCH] Bug 33277: Don't search thesaurus when heading 'notspecified' --- C4/Heading.pm | 5 ++++- t/db_dependent/Heading.t | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/C4/Heading.pm b/C4/Heading.pm index 5c393b4d53..0e45a66624 100644 --- a/C4/Heading.pm +++ b/C4/Heading.pm @@ -211,7 +211,10 @@ sub _search { push @value, $self->{'search_form'}; } - if ( $thesaurus ) { + # FIXME we don't have a method for negative search + # but 'notspecified' should be 'not n' - the best + # we can achieve currently is to ignore the thesaurus + if ( $thesaurus && $thesaurus ne 'notspecified' ) { push @marclist, 'thesaurus'; push @and_or, 'and'; push @excluding, ''; diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t index 0df92e51db..aa39c4f767 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 => 7; + plan tests => 8; t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); @@ -111,6 +111,15 @@ subtest "_search tests" => sub { ]; is_deeply( $terms, $expected_terms, "Search formed as expected with second indicator 7 and subfield 2"); + $field = MARC::Field->new( '650', ' ', '4', 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' } }, + ]; + is_deeply( $terms, $expected_terms, "Search doesn't specify thesaurus when heading marked as 'notspecified'"); + $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,' ); $heading = C4::Heading->new_from_field($field); ($search_query) = $heading->_search( 'match-heading' ); -- 2.30.2