Bug 26009: Add facet size to home/holdingbranch
authorNick Clemens <nick@bywatersolutions.com>
Fri, 17 Jul 2020 16:23:42 +0000 (16:23 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Aug 2020 14:54:40 +0000 (16:54 +0200)
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 <mspringer@mylakelibrary.org>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/SearchEngine/Elasticsearch/QueryBuilder.pm
t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t

index 3c6aaa4..4d69dcf 100644 (file)
@@ -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;
 }
index 7ef261c..ee8b81a 100644 (file)
@@ -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();