From 2de8fd9e33942f96fa026fd1feb49aea7007dacd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 5 Oct 2015 17:15:01 +0100 Subject: [PATCH] Bug 12478: Take the FacetMaxCount pref into account The system preference FacetMaxCount should work as expected with ES. Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 7 ++++++- Koha/SearchEngine/Elasticsearch/Search.pm | 5 +++-- opac/opac-search.pl | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 30bf6f8f73..67d06ba164 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/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); diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 2d67d0be32..0950139fad 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/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, diff --git a/opac/opac-search.pl b/opac/opac-search.pl index c61bbbd438..f68fb9f99c 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -536,7 +536,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,$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,$query_type) = $builder->build_query_compat(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang, { expanded_facet => $expanded_facet }); sub _input_cgi_parse { my @elements; -- 2.39.5