Bug 31925: Make QueryBuilder reuse the shared thesaurus/008 lookup
Koha::SearchEngine::Elasticsearch::QueryBuilder kept its own copy of the thesaurus-name to 008/11-code table used when building "thesaurus" search queries against authority records. The previous commit moved that same table to Koha::Authority as a shared lookup. This commit deletes QueryBuilder's duplicate and points $thesaurus_to_value at $Koha::Authority::MARC21_THESAURUS_TO_CONTROL_FIELD_008_11 instead, so there is only one place to update if the code list ever changes. Pure refactor: $thesaurus_to_value keeps its existing name and contents, and build_authorities_query_compat() is unchanged, so query behaviour is identical before and after. Sponsored-by: Heythrop Library <https://heythroplibrary.co.uk/> Signed-off-by: Clemens Gresser <cgresser@jesuit.org.uk> Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org> Signed-off-by: David Cook <dcook@prosentient.com.au> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
4bfb9abc68
commit
9186341ddd
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue