From 4dd1672c1b2f15e0b6be6071b6915c927c3a2ecc Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 17 Jul 2020 16:23:42 +0000 Subject: [PATCH] Bug 26009: Add facet size to home/holdingbranch To test: 0 - Set DisplayLibraryFacets to 'both' and FacetMaxCount to 20 1 - Have more than 10 branches 2 - Have items in each of those branches 3 - Enable ES, set system preference SearchEngine to Elasticsearch 4 - Search for '*' 5 - Expand homebranch/holdingbranch facets 6 - Note you only get 10 7 - Apply patch 8 - Repeat search 9 - Now you get all your facets Signed-off-by: Michael Springer Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 4 ++-- t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 3c6aaa42b1..4d69dcf95b 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -132,11 +132,11 @@ sub build_query { my $display_library_facets = C4::Context->preference('DisplayLibraryFacets'); if ( $display_library_facets eq 'both' or $display_library_facets eq 'home' ) { - $res->{aggregations}{homebranch} = { terms => { field => "homebranch__facet" } }; + $res->{aggregations}{homebranch} = { terms => { field => "homebranch__facet", size => $size } }; } if ( $display_library_facets eq 'both' or $display_library_facets eq 'holding' ) { - $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet" } }; + $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet", size => $size } }; } return $res; } diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 7ef261c6c9..ee8b81a4a7 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -216,7 +216,7 @@ subtest 'build_authorities_query_compat() tests' => sub { }; subtest 'build_query tests' => sub { - plan tests => 50; + plan tests => 51; my $qb; @@ -244,9 +244,11 @@ subtest 'build_query tests' => sub { ); t::lib::Mocks::mock_preference('FacetMaxCount','37'); + t::lib::Mocks::mock_preference('DisplayLibraryFacets','both'); $query = $qb->build_query('test', %options); ok( defined $query->{aggregations}{ccode}{terms}{size},'we need to ask for a size or we get only 5 facet' ); is( $query->{aggregations}{ccode}{terms}{size}, 37,'we ask for the size as defined by the syspref FacetMaxCount'); + is( $query->{aggregations}{homebranch}{terms}{size}, 37,'we ask for the size as defined by the syspref FacetMaxCount fir homebranch'); t::lib::Mocks::mock_preference('DisplayLibraryFacets','both'); $query = $qb->build_query(); -- 2.39.5