@@ -, +, @@ --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 7 ++++++- Koha/SearchEngine/Elasticsearch/Search.pm | 5 +++-- opac/opac-search.pl | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -46,6 +46,7 @@ use List::MoreUtils qw/ each_array /; use Modern::Perl; use URI::Escape; +use C4::Context; use Data::Dumper; # TODO remove =head2 build_query @@ -118,6 +119,9 @@ sub build_query { 'su-geo' => { terms => { field => "su-geo__facet" } }, se => { terms => { field => "se__facet" } }, }; + if ( my $ef = $options{expanded_facet} ) { + $res->{facets}{$ef}{terms}{size} = C4::Context->preference('FacetMaxCount'); + }; return $res; } @@ -181,7 +185,7 @@ reproduce this search, and C<$query_desc> set to something else. sub build_query_compat { my ( $self, $operators, $operands, $indexes, $orig_limits, $sort_by, $scan, - $lang ) + $lang, $params ) = @_; #die Dumper ( $self, $operators, $operands, $indexes, $orig_limits, $sort_by, $scan, $lang ); @@ -215,6 +219,7 @@ sub build_query_compat { $query_str =~ s/^ AND //; my %options; $options{sort} = \@sort_params; + $options{expanded_facet} = $params->{expanded_facet}; my $query = $self->build_query( $query_str, %options ); #die Dumper($query); --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ a/Koha/SearchEngine/Elasticsearch/Search.pm @@ -148,6 +148,7 @@ sub search_compat { my %options; $options{offset} = $offset; + $options{expanded_facet} = $expanded_facet; my $results = $self->search($query, undef, $results_per_page, %options); # Convert each result into a MARC::Record @@ -378,7 +379,7 @@ Converts elasticsearch facets types to the form that Koha expects. It expects the ES facet name to match the Koha type, for example C, C, C, etc. -C<$expanded_facet> is the facet that we want to show 10 entries for, rather +C<$expanded_facet> is the facet that we want to show FacetMaxCount entries for, rather than just 5 like normal. =cut @@ -415,7 +416,7 @@ sub _convert_facets { next if !exists( $type_to_label{$type} ); # We restrict to the most popular $limit !results - my $limit = ( $type eq $exp_facet ) ? 10 : 5; + my $limit = ( $type eq $exp_facet ) ? C4::Context->preference('FacetMaxCount') : 5; my $facet = { type_id => $type . '_id', expand => $type, --- a/opac/opac-search.pl +++ a/opac/opac-search.pl @@ -505,7 +505,7 @@ my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_ my @results; ## I. BUILD THE QUERY -( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = $builder->build_query_compat(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang); +( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = $builder->build_query_compat(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang, { expanded_facet => $expanded_facet }); #die Dumper( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type); sub _input_cgi_parse { --