Bugzilla – Attachment 132361 Details for
Bug 27113
Elasticsearch: Autocomplete in search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27113: (follow-up) QA Tests
Bug-27113-follow-up-QA-Tests.patch (text/plain), 10.49 KB, created by
The Minh Luong
on 2022-03-28 19:53:42 UTC
(
hide
)
Description:
Bug 27113: (follow-up) QA Tests
Filename:
MIME Type:
Creator:
The Minh Luong
Created:
2022-03-28 19:53:42 UTC
Size:
10.49 KB
patch
obsolete
>From 7e39f80f57ee4c741a397a9e7ddc7eed0a79fab8 Mon Sep 17 00:00:00 2001 >From: Ivan Dziuba <ivan.dziuba@inlibro.com> >Date: Fri, 23 Apr 2021 17:08:55 -0400 >Subject: [PATCH] Bug 27113: (follow-up) QA Tests > >Bug 27113: (follow-up) QA Tests (2) > >Bug 27113: (follow-up) Fixup warnings. > >TEST PLAN >Important! In this patch we need to do reindex ElasticSearch. ElasticSearch must have all information in his index. >1. Go Intranet -> Preference -> SearchEngine -> ElasticSearch >!! APPLY PATCH !! >2. Mapping is good (Intranet -> Catalog -> Search engine configuration (Elasticsearch) ). >!Recommended 'Reset Mapping' -> 'Yes' >3. In your koha-conf.xml file you must have good <index_name> for <elasticsearch> and version ES >4. Update Preference: >./installer/data/mysql/updatedatabase.pl >If that passe good you can look the lines: > - DEV atomic update: bug_27113-elasticsearch_autocomplete_input_search.perl > - Upgrade to XXX done : Bug 27113 - Autocomplete input on main page with elasticsearch >5. After that we can look two options in the preferences: >- IntranetAutocompleteElasticSearch; >- OPACAutocompleteElasticSearch; >4. For add information in the index we must run script for reindexing: >./misc/search_tools/rebuild_elasticsearch.pl -v -d >5. Waiting for the end of indexing >6. Go on Preference and find : >- IntranetAutocompleteElasticSearch; >- OPACAutocompleteElasticSearch; >Value "Show" turn on autocomplete. >7. Now we have Autocomplete for Intranet/OPAC search input (advanced search also). > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/SearchEngine/Elasticsearch/Browse.pm | 69 +++++++++++++++++-- > api/elasticsearch/elasticsearch.pl | 13 ++-- > .../prog/en/includes/js_includes.inc | 2 +- > .../bootstrap/en/includes/opac-bottom.inc | 2 +- > opac/svc/elasticsearch/opac-elasticsearch.pl | 13 ++-- > t/Koha_SearchEngine_Elasticsearch_Browse.t | 30 ++++++++ > 6 files changed, 111 insertions(+), 18 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, ["<strong>"], ["</strong>"]); >- > 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 << <robin@catalyst.net.nz> >> > >+=item Ivan Dziuba << <ivan.dziuba@inlibro.com> >> >+ > =back > > =cut >diff --git a/api/elasticsearch/elasticsearch.pl b/api/elasticsearch/elasticsearch.pl >index 86890dcaab..09a79bc045 100755 >--- a/api/elasticsearch/elasticsearch.pl >+++ b/api/elasticsearch/elasticsearch.pl >@@ -14,13 +14,13 @@ my $cgi = CGI->new; > my $session = CGI::Session->new(); > > $session->param(-name=>'analyzer', -value=>"autocomplete"); >-$session->param(-name=>'prefix', -value=>$cgi->param("prefix")); >-$session->param(-name=>'q', -value=>$cgi->param("q")); >-$session->param(-name=>'key', -value=>$cgi->param("key")); >-$session->param(-name=>'token_counter', -value=>$cgi->param("token_counter")); >+$session->param(-name=>'prefix', -value=>$cgi->multi_param("prefix")); >+$session->param(-name=>'q', -value=>$cgi->multi_param("q")); >+$session->param(-name=>'key', -value=>$cgi->multi_param("key")); >+$session->param(-name=>'token_counter', -value=>$cgi->multi_param("token_counter")); > $session->expire('+1h'); > >-if ($session->param("key") == "autocomplete") { >+if ($session->param("key") eq "autocomplete") { > my @prefix = split /,/, $session->param("prefix"); > #fields for autocomplete > my $length = scalar @prefix; >@@ -49,6 +49,7 @@ else { > } > > sub response404JSON { >+ my $res = CGI->new; > my $json = JSON->new->utf8; > my $header_type = "application/json"; > my $header_status = "404"; >@@ -56,7 +57,7 @@ sub response404JSON { > "error" => "No data", > "description" => "Bad request", > }); >- print $cgi->header( >+ print $res->header( > -type => $header_type, > -charset => "utf-8", > -status => $header_status >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 9fb8a0d46d..9459f527f9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >@@ -173,6 +173,6 @@ > [% END %] > <!-- Intranet inc JS IntranetAutocompleteElasticSearch --> > [% IF ( Koha.Preference('IntranetAutocompleteElasticSearch') ) %] >- [% Asset.js("js/elasticsearch/autocomplete.js") %] >+[% Asset.js("js/elasticsearch/autocomplete.js") | $raw %] > [% END %] > <!-- / js_includes.inc --> >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 751770a8db..d52c123bfc 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >@@ -295,7 +295,7 @@ $(document).ready(function() { > [% PROCESS jsinclude %] > <!-- OPAC *.inc JS OPACAutocompleteElasticSearch --> > [% 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') ) %] > <script> >diff --git a/opac/svc/elasticsearch/opac-elasticsearch.pl b/opac/svc/elasticsearch/opac-elasticsearch.pl >index e9dfa0a81f..8934cd50c6 100755 >--- a/opac/svc/elasticsearch/opac-elasticsearch.pl >+++ b/opac/svc/elasticsearch/opac-elasticsearch.pl >@@ -14,15 +14,15 @@ my $cgi = CGI->new; > my $session = CGI::Session->new(); > > $session->param(-name=>'analyzer', -value=>"autocomplete"); >-$session->param(-name=>'prefix', -value=>$cgi->param("prefix")); >-$session->param(-name=>'q', -value=>$cgi->param("q")); >-$session->param(-name=>'key', -value=>$cgi->param("key")); >-$session->param(-name=>'token_counter', -value=>$cgi->param("token_counter")); >+$session->param(-name=>'prefix', -value=>$cgi->multi_param("prefix")); >+$session->param(-name=>'q', -value=>$cgi->multi_param("q")); >+$session->param(-name=>'key', -value=>$cgi->multi_param("key")); >+$session->param(-name=>'token_counter', -value=>$cgi->multi_param("token_counter")); > $session->expire('+1h'); > > my $iskey = 0; > >-if ($session->param("key") == "autocomplete") { >+if ($session->param("key") eq "autocomplete") { > $iskey = 1; > my @prefix = split /,/, $session->param("prefix"); > #fields for autocomplete >@@ -53,6 +53,7 @@ if ($iskey == 0) { > } > > sub response404JSON { >+ my $res = CGI->new; > my $json = JSON->new->utf8; > my $header_type = "application/json"; > my $header_status = "404"; >@@ -60,7 +61,7 @@ sub response404JSON { > "error" => "No data", > "description" => "Bad request", > }); >- print $cgi->header( >+ print $res->header( > -type => $header_type, > -charset => "utf-8", > -status => $header_status >diff --git a/t/Koha_SearchEngine_Elasticsearch_Browse.t b/t/Koha_SearchEngine_Elasticsearch_Browse.t >index 986c4ba658..4e93e2c42d 100755 >--- a/t/Koha_SearchEngine_Elasticsearch_Browse.t >+++ b/t/Koha_SearchEngine_Elasticsearch_Browse.t >@@ -65,4 +65,34 @@ subtest "_build_query tests" => sub { > }, 'Fuzziness and size specified'); > }; > >+subtest "_build_query_autocomplete tests" => sub { >+ plan tests => 1; >+ >+ my $browse = Koha::SearchEngine::Elasticsearch::Browse->new({index=>'dummy'}); >+ >+ my $q = $browse->_build_query_autocomplete('a', 'title', 'autocomplete'); >+ >+ is_deeply($q, { >+ _source => ["title"], >+ query => { >+ match => { >+ "title.autocomplete" => { >+ query => 'a', >+ operator => 'and' >+ } >+ } >+ }, >+ highlight => { >+ number_of_fragments => 1, >+ fragment_size => 100, >+ pre_tags => ["<strong>"], >+ post_tags => ["</strong>"], >+ fields => { >+ "title.autocomplete" => {} >+ } >+ } >+ }, 'Autocomplete for title is specified'); >+ >+}; >+ > done_testing(); >-- >2.25.1
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 27113
:
114168
|
114169
|
114945
|
115117
|
116293
|
119979
|
120028
|
120029
|
120084
|
120088
|
120109
|
120140
|
120141
|
120806
|
121497
|
121498
|
121555
|
121556
|
121557
|
121558
|
131207
|
131208
|
131209
|
131210
|
131211
|
132360
|
132361
|
132362
|
132363
|
132364
|
132808
|
132945
|
132946
|
133042
|
133045
|
133407
|
133409
|
133410
|
136312
|
136456
|
136457
|
136464
|
136465
|
136653
|
136657
|
136658
|
136659
|
136660
|
137436
|
137437
|
137438
|
137439
|
137780
|
137781
|
137782
|
137783
|
139624
|
141466
|
145167
|
146015
|
159769
|
159770
|
159771
|
159772
|
159773
|
159774
|
159775
|
160134
|
160135
|
160136
|
160137
|
160138
|
160139
|
160140
|
160141
|
160142
|
161076
|
161077
|
163826
|
165895
|
165896
|
165897
|
165898
|
165899
|
165900
|
165901
|
165902
|
165903
|
165904
|
165913
|
165922