Bugzilla – Attachment 89850 Details for
Bug 22903
Elasticsearch, dynamic display when you refine your search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22903: Elasticsearch, dynamic display when you refine your search
Bug-22903-Elasticsearch-dynamic-display-when-you-r.patch (text/plain), 10.19 KB, created by
axel Amghar
on 2019-05-16 14:34:05 UTC
(
hide
)
Description:
Bug 22903: Elasticsearch, dynamic display when you refine your search
Filename:
MIME Type:
Creator:
axel Amghar
Created:
2019-05-16 14:34:05 UTC
Size:
10.19 KB
patch
obsolete
>From ebcddab1edee78151958dfae474a2489f522a142 Mon Sep 17 00:00:00 2001 >From: Axel Amghar <axel.amghar@biblibre.com> >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 %] > <li> >+ > [% IF facet.active %] > [% local_url = BLOCK %][% url | $raw %][% "&nolimit=" _ facet.type_link_value _ ":" _ facet.facet_link_value | url %][% END %] > <span class="facet-label">[% facet.facet_label_value | html %]</span> >@@ -46,11 +49,20 @@ > [% END %] > [% END %] > </li> >+ [% i = i+1 %] >+ [% IF ( i == 6 ) %] >+ <div id="hide_[% facets_loo.type_link_value |html %]"> >+ [% END %] >+ > [% END %] >- [% IF ( facets_loo.expandable ) %] >- <li class="showmore"> >- <a href="[% url | url %][% IF offset %]&offset=[% offset | uri %][% END %]&expand=[% facets_loo.expand | uri %]#[% facets_loo.type_id | uri %]">Show more</a> >- </li> >+ [% IF ( i >= 6 ) %] >+ </div> >+ [% END %] >+ >+ [% IF ( i > 6 ) %] >+ <li class="showmore"> >+ <a id="link_[% facets_loo.type_link_value |html %]" href="" >Show more</a> >+ </li> > [% END %] > </ul></li> > [% 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(); > } > </script> >+ >+ <script> >+ //script of facets.inc >+ $(document).ready( function () { >+ >+ [% FOREACH facets_loo IN facets_loop %] >+ $("#hide_[% facets_loo.type_link_value |html %]").css("display", "none"); >+ [% END %] >+ >+ const hide = () => { >+ [% FOREACH facets_loo IN facets_loop %] >+ >+ $("#link_[% facets_loo.type_link_value |html %]").click(function(e){ >+ e.preventDefault(); >+ $("#hide_[% facets_loo.type_link_value | html %]").css("display", "block"); >+ $("#link_[% facets_loo.type_link_value | html %]").parent().html('<a id="back_[% facets_loo.type_link_value | html %]" href="" >Show less</a>'); >+ show(); >+ }); >+ [% END %] >+ }; >+ >+ const show = () => { >+ [% FOREACH facets_loo IN facets_loop %] >+ >+ $("#back_[% facets_loo.type_link_value | html %]").click(function(e){ >+ e.preventDefault(); >+ $("#hide_[% facets_loo.type_link_value | html %]").css("display", "none"); >+ $("#back_[% facets_loo.type_link_value | html %]").parent().html('<a id="link_[% facets_loo.type_link_value | html %]" href="" >Show more</a>'); >+ hide(); >+ }); >+ [% END %] >+ }; >+ >+ hide(); >+ }); >+ >+ </script> > [% END %] > > [% INCLUDE 'intranet-bottom.inc' %] >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22903
:
89822
|
89823
|
89829
| 89850 |
89880