Bug 29561: Remove blank facets

This patch strips the blank facets from the ES aggregations, this seems
to only affect language fields currently, but could affect any facetable field
that can contain blank values

To test:
1 - Have Koha running Elasticsearch with standard test data,
    or add some records with blank values in the 008/35-37
2 - Search for 'a'
3 - Look at the language facets, they should appear normal
4 - Browse to:
    http://localhost:8081/cgi-bin/koha/catalogue/search.pl?idx=&q=a&sort_by=relevance_dsc&count=20&limit=ln:
5 - Note there is now an 'x' under the Languages facet - to remove a limit you cannot see
6 - Apply patch
7 - Reload
8 - Note the x is not there
9 - Inspect HTML, confirm no blank link under language facets

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit eeb12f8a52)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2021-11-23 14:42:54 +00:00 committed by Lucas Gass
parent 5b6b095f1f
commit 3fb3a8c7d6

View file

@ -492,6 +492,7 @@ sub _convert_facets {
$limit = @{ $data->{buckets} } if ( $limit > @{ $data->{buckets} } );
foreach my $term ( @{ $data->{buckets} }[ 0 .. $limit - 1 ] ) {
my $t = $term->{key};
next unless $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;
if ( exists( $special{$type} ) ) {