From af92b3172d453de65739bbe23c19fc4b7032226e 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: 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 --- 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 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 15 deletions(-) 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