From 35b28dce5a82499c18d63156a402905dee4d6019 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Wed, 17 Apr 2024 08:10:46 +0000 Subject: [PATCH] Bug 14007: Hide hidden itemtypes in opac facets. Test plan: * Start koha-testing-docker with elasticsearch or opensearch (e.g., ku-es7) * Make sure there is a built index for Elastic/OpenSearch: > koha-elasticsearch --reset --rebuild kohadev * Search for "book" in opac and note the facet values for itemtype * Change systempreference SearchEngine to ElasticSearch * Search for "book" in opac and note the facet values for itemtype * Go to the adminstration view of one of the itemtypes (for instance Visual Materials) and check "Hide in OPAC". * Search for "book" in opac and make sure the hidden itemtype do not appear as facet. * Search for "book" in staff interface and make sure the hidden itemtype still does appear as a facet. * Change back the systemprefence to Zebra * Search for "book" in opac and make sure the hidden itemtype do not appear as facet. * Search for "book" in staff interface and make sure the hidden itemtype still does appear as a facet. Signed-off-by: David Nind --- C4/Search.pm | 14 ++++++++++++++ Koha/SearchEngine/Elasticsearch/Search.pm | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/C4/Search.pm b/C4/Search.pm index ea70377373..7de39a68a5 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -620,6 +620,20 @@ sub GetFacets { $facets = _get_facets_from_records( $rs ); } + if ( C4::Context->interface eq 'opac' ) { + for my $k ( keys %$facets ) { + if ( $k eq 'itype' ) { + my $itemtypes = Koha::ItemTypes->new; + for my $fv ( keys %{ $facets->{$k} } ) { + my $itemtype = $itemtypes->find($fv); + if ( defined $itemtype && $itemtype->hideinopac ) { + delete $facets->{$k}->{$fv}; + } + } + } + } + } + return $facets; } diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 37b57d9f8c..772b844fb1 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -458,6 +458,9 @@ sub _convert_facets { holdingbranch => $library_names, homebranch => $library_names ); + + my @hidden_itemtypes = map { $_->itemtype } ( grep { $opac && $_->hideinopac } @itypes ); + my @facets; $exp_facet //= ''; while ( my ( $type, $data ) = each %$es ) { @@ -478,6 +481,7 @@ sub _convert_facets { next unless length($t); # FIXME Currently we cannot search for an empty faceted field i.e. ln:"" to find records missing languages, though ES does count them correctly my $c = $term->{doc_count}; my $label; + next if $type eq 'itype' && grep { $_ eq $t } @hidden_itemtypes; if ( exists( $special{$type} ) ) { $label = $special{$type}->{$t} // $t; } -- 2.39.2