diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 427b041ebe..e1299d74dd 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -47,6 +47,7 @@ use URI::Escape qw( uri_escape_utf8 ); use C4::Context; use Koha::Exceptions; +use Koha::Authority; use Koha::Caches; use Koha::AuthorisedValueCategories; @@ -608,23 +609,9 @@ our $koha_to_index_name = { all => '' }; -# Note that sears and aat map to 008/11 values here -# but don't appear in C4/Heading/MARC21 thesaurus -# because they don't have values in controlled field indicators -# https://www.loc.gov/marc/authority/ad008.html -our $thesaurus_to_value = { - lcsh => 'a', - lcac => 'b', - mesh => 'c', - nal => 'd', - notapplicable => 'n', - cash => 'k', - rvm => 'v', - aat => 'r', - sears => 's', - notdefined => 'z', - notspecified => '|' -}; +# Delegates to Koha::Authority's table so there is a single source of +# truth for thesaurus-name -> 008/11-code (bug 31925). +our $thesaurus_to_value = $Koha::Authority::MARC21_THESAURUS_TO_CONTROL_FIELD_008_11; sub build_authorities_query_compat { my ( diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index d7b9528145..47ca31b883 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -85,7 +85,7 @@ $se->mock( subtest 'build_authorities_query_compat() tests' => sub { - plan tests => 81; + plan tests => 83; my $qb; @@ -249,6 +249,24 @@ subtest 'build_authorities_query_compat() tests' => sub { "If mapping found for marclist the index is passed through converted" ); + # Thesaurus value mapping delegates to Koha::Authority (bug 31925) + $query = $qb->build_authorities_query_compat( + ['thesaurus'], undef, undef, ['contains'], ['lcsh'], 'AUTH_TYPE', + 'asc' + ); + is( + $query->{query}->{bool}->{must}[0]->{query_string}->{query}, 'a*', + "thesaurus value 'lcsh' is still translated to 008/11 code 'a'" + ); + $query = $qb->build_authorities_query_compat( + ['thesaurus'], undef, undef, ['contains'], ['mesh'], 'AUTH_TYPE', + 'asc' + ); + is( + $query->{query}->{bool}->{must}[0]->{query_string}->{query}, 'c*', + "thesaurus value 'mesh' is still translated to 008/11 code 'c'" + ); + }; subtest 'build_query tests' => sub {