From 978427c2dcf6a4cd1b6a5ef7eed51e1b475fa14a Mon Sep 17 00:00:00 2001 From: Ivan Dziuba Date: Fri, 23 Apr 2021 17:08:55 -0400 Subject: [PATCH] Bug 27113: (follow-up) QA Tests Bug 27113: (follow-up) QA Tests (2) --- Koha/SearchEngine/Elasticsearch/Browse.pm | 69 +++++++++++++++++-- .../prog/en/includes/js_includes.inc | 2 +- .../bootstrap/en/includes/opac-bottom.inc | 2 +- t/Koha_SearchEngine_Elasticsearch_Browse.t | 30 ++++++++ 4 files changed, 97 insertions(+), 6 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Browse.pm b/Koha/SearchEngine/Elasticsearch/Browse.pm index 57c0a74023..78f93832c7 100644 --- a/Koha/SearchEngine/Elasticsearch/Browse.pm +++ b/Koha/SearchEngine/Elasticsearch/Browse.pm @@ -40,7 +40,7 @@ Koha::SearchEngine::ElasticSearch::Browse - browse functions for Elasticsearch This provides an easy interface to the "browse" functionality. Essentially, it does a fast prefix search on defined fields. The fields have to be marked -as "suggestible" in the database when indexing takes place. +as "suggestible" in the database when indexing takes place(no action required for autocomplete). =head1 METHODS @@ -162,13 +162,25 @@ sub _build_query { return $query; } +=head2 autocomplete_one_idx + + my $query = $self->autocomplete_one_idx($cgi_q, $prefix, $analyzer, $token_counter); + +Does a prefix search for C<$prefix> (only one prefix), looking for C<$cgi_q> , using analyzer C<$analyzer> , +C<$token_counter> is used for identify which word to use in autocomplete + +=cut + +=head3 Returns + +This returns an arrayref of hashrefs with highlights. Each hashref contains a "text" element that contains the field as returned. + +=cut + sub autocomplete_one_idx { my ($self, $cgi_q, $prefix, $analyzer, $token_counter) = @_; my @source; my $elasticsearch = $self->get_elasticsearch(); - # we can change these variables - my ($nb_fragments, $size_fragment, $pre_tags, $post_tags) = (1, 100, [""], [""]); - my $query = $self->_build_query_autocomplete($cgi_q, $prefix, $analyzer); my $res = $elasticsearch->search( index => $self->index_name, @@ -181,6 +193,22 @@ sub autocomplete_one_idx { return $res; } +=head2 autocomplete_idx + + my $query = $self->autocomplete_idx($cgi_q, $prefix, $analyzer, $token_counter); + +Does a prefix search for C<$prefix> (many prefix), looking for C<$cgi_q>, using analyzer C<$analyzer>, +C<$token_counter> is used for identify which word to use in autocomplete + +=cut + +=head3 Returns + +This returns an arrayref for all prefix of hashrefs with highlights. Each hashref contains a "text" element +that contains the field as returned. + +=cut + sub autocomplete_idx { my ($self, $cgi_q, $prefix, $analyzer, $token_counter) = @_; my %results; @@ -195,6 +223,37 @@ sub autocomplete_idx { return \%results; } +=head2 _build_query_autocomplete + + my $query = $self->_build_query_autocomplete($cgi_q, $prefix, $analyzer); + +Arguments: + +=over 4 + +=item cgi_q + +GET request + +=item prefix + +Field(s) for autocomplete (title, author, etc...) + +=item analyzer + +Name of analyzer wich we use for autocomplete + +=back + +=cut + +=head3 Returns + +This returns an arrayref for all prefix of hashrefs with highlights. Each hashref contains a "text" element +that contains the field as returned. + +=cut + sub _build_query_autocomplete { my ($self, $cgi_q, $prefix, $analyzer) = @_; my (@source); @@ -236,6 +295,8 @@ __END__ =item Robin Sheat << >> +=item Ivan Dziuba << >> + =back =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc index 371c2d9664..ba2f010393 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -146,6 +146,6 @@ [% END %] [% IF ( Koha.Preference('IntranetAutocompleteElasticSearch') ) %] - [% Asset.js("js/elasticsearch/autocomplete.js") %] +[% Asset.js("js/elasticsearch/autocomplete.js") | $raw %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index 29cc43ac08..827b96e133 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -320,7 +320,7 @@ $(document).ready(function() { [% PROCESS jsinclude %] [% IF ( Koha.Preference('OPACAutocompleteElasticSearch') ) %] - [% Asset.js("js/opac-elasticsearch/opac-autocomplete.js") %] + [% Asset.js("js/opac-elasticsearch/opac-autocomplete.js") | $raw %] [% END %] [% IF ( Koha.Preference('OPACUserJS') ) %]