From ebcddab1edee78151958dfae474a2489f522a142 Mon Sep 17 00:00:00 2001 From: Axel Amghar Date: Thu, 16 May 2019 10:39:17 +0200 Subject: [PATCH] Bug 22903: Elasticsearch, dynamic display when you refine your search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To test: With Elasticsearch-> Without the patch: - check if you have your SysPref SearchEngine with Elasticsearch as value, - put your SysPref FacetMaxCount at 10, - search in the catalog "a" and then in Refine your search click on show more (just to see how it works), - then search with special characters like "é", ç" ... and make the same test, the research should be wrong when you click on show more and the page is realoaded. Then apply the patch: - and make the same with a classic reasearch, then with special characters, - verify that when you click on show more the page isn't realoded and the reasearch is correct. - same with show less - and finnaly, add some facets and test show more/less With Zerbra -> - put your SysPref SearchEngine with Zebra as value, - and make the same thing as elasticsearch --- C4/Search.pm | 14 +++----- Koha/SearchEngine/Elasticsearch/Search.pm | 13 +++----- catalogue/search.pl | 4 +-- .../intranet-tmpl/prog/en/includes/facets.inc | 20 +++++++++--- .../prog/en/modules/catalogue/results.tt | 37 ++++++++++++++++++++++ 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 559abea..bb7ad64 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -326,10 +326,9 @@ See verbse embedded documentation. sub getRecords { my ( $koha_query, $simple_query, $sort_by_ref, $servers_ref, - $results_per_page, $offset, $expanded_facet, $branches, - $itemtypes, $query_type, $scan, $opac + $results_per_page, $offset, $branches, $itemtypes, + $query_type, $scan, $opac ) = @_; - my @servers = @$servers_ref; my @sort_by = @$sort_by_ref; $offset = 0 if $offset < 0; @@ -442,6 +441,7 @@ sub getRecords { sub { my ( $i, $size ) = @_; my $results_hash; + my $facetMaxCount = C4::Context->preference('FacetMaxCount') || 10; # loop through the results $results_hash->{'hits'} = $size; @@ -528,10 +528,7 @@ sub getRecords { ) { $number_of_facets++; - if ( ( $number_of_facets <= 5 ) - || ( $expanded_facet eq $link_value ) - || ( $facets_info->{$link_value}->{'expanded'} ) - ) + if ( $number_of_facets <= $facetMaxCount ) { # Sanitize the link value : parenthesis, question and exclamation mark will cause errors with CCL @@ -612,8 +609,7 @@ sub getRecords { # handle expanded option unless ( $facets_info->{$link_value}->{'expanded'} ) { $expandable = 1 - if ( ( $number_of_facets > 5 ) - && ( $expanded_facet ne $link_value ) ); + if ( $number_of_facets > 5 ); } push @facets_loop, { diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index a4b4e84..4ac8d9d 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -145,15 +145,15 @@ get ignored here, along with some other things (like C<@servers>.) sub search_compat { my ( $self, $query, $simple_query, $sort_by, - $servers, $results_per_page, $offset, $expanded_facet, + $servers, $results_per_page, $offset, $branches, $query_type, $scan ) = @_; my %options; if ( !defined $offset or $offset < 0 ) { $offset = 0; } + $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 @@ -171,7 +171,7 @@ sub search_compat { my %result; $result{biblioserver}{hits} = $hits->{'total'}; $result{biblioserver}{RECORDS} = \@records; - return (undef, \%result, $self->_convert_facets($results->{aggregations}, $expanded_facet)); + return (undef, \%result, $self->_convert_facets($results->{aggregations})); } =head2 search_auth_compat @@ -430,7 +430,7 @@ than just 5 like normal. =cut sub _convert_facets { - my ( $self, $es, $exp_facet ) = @_; + my ( $self, $es) = @_; return if !$es; @@ -471,17 +471,14 @@ sub _convert_facets { homebranch => $library_names ); my @facets; - $exp_facet //= ''; while ( my ( $type, $data ) = each %$es ) { next if !exists( $type_to_label{$type} ); # We restrict to the most popular $limit !results - my $limit = ( $type eq $exp_facet ) ? C4::Context->preference('FacetMaxCount') : 5; + my $limit = C4::Context->preference('FacetMaxCount') || 5 ; my $facet = { type_id => $type . '_id', expand => $type, - expandable => ( $type ne $exp_facet ) - && ( @{ $data->{buckets} } > $limit ), "type_label_$type_to_label{$type}{label}" => 1, type_link_value => $type, order => $type_to_label{$type}{order}, diff --git a/catalogue/search.pl b/catalogue/search.pl index 514c4a9..46eaf07 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -459,8 +459,6 @@ my $offset = $params->{'offset'} || 0; $offset = 0 if $offset < 0; my $page = $cgi->param('page') || 1; #my $offset = ($page-1)*$results_per_page; -my $expanded_facet = $params->{'expand'}; - # Define some global variables my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type); @@ -536,7 +534,7 @@ eval { my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; ( $error, $results_hashref, $facets ) = $searcher->search_compat( $query, $simple_query, \@sort_by, \@servers, - $results_per_page, $offset, $expanded_facet, undef, + $results_per_page, $offset, undef, $itemtypes, $query_type, $scan ); }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc index ea7a46d..3cb2bd1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -30,10 +30,13 @@ [% IF ( sort_by ) %] [% url = BLOCK %][% url | $raw %][% "&sort_by=" _ sort_by | url %][% END %] [% END %] + [% SET i = 1 %] + [% FOREACH facet IN facets_loo.facets %] [% IF facets_loo.type_label_CollectionCodes %][% SET facet.facet_label_value = AuthorisedValues.GetByCode('CCODE',facet.facet_label_value,0) || facet.facet_label_value %][% END %] [% IF facets_loo.type_label_Language %][% SET facet.facet_label_value = Languages.GetByISOCode(lang,facet.facet_label_value) || facet.facet_label_value %][% END %]
  • + [% IF facet.active %] [% local_url = BLOCK %][% url | $raw %][% "&nolimit=" _ facet.type_link_value _ ":" _ facet.facet_link_value | url %][% END %] [% facet.facet_label_value | html %] @@ -46,11 +49,20 @@ [% END %] [% END %]
  • + [% i = i+1 %] + [% IF ( i == 6 ) %] + + [% END %] + + [% IF ( i > 6 ) %] +
  • + Show more +
  • [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index 626b238..88c3216 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -936,6 +936,43 @@ placeHold(); } + + [% END %] [% INCLUDE 'intranet-bottom.inc' %] -- 2.7.4