Bug 12478: Take the FacetMaxCount pref into account
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 5 Oct 2015 16:15:01 +0000 (17:15 +0100)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Tue, 26 Apr 2016 20:20:11 +0000 (20:20 +0000)
The system preference FacetMaxCount should work as expected with ES.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Koha/SearchEngine/Elasticsearch/QueryBuilder.pm
Koha/SearchEngine/Elasticsearch/Search.pm
opac/opac-search.pl

index 30bf6f8..67d06ba 100644 (file)
@@ -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);
index 2d67d0b..0950139 100644 (file)
@@ -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<itype>,
 C<au>, C<su-to>, 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,
index c61bbbd..f68fb9f 100755 (executable)
@@ -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;