Bugzilla – Attachment 120141 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), 6.03 KB, created by
Ivan Dziuba
on 2021-04-23 21:24:54 UTC
(
hide
)
Description:
Bug 27113: (follow-up) QA Tests
Filename:
MIME Type:
Creator:
Ivan Dziuba
Created:
2021-04-23 21:24:54 UTC
Size:
6.03 KB
patch
obsolete
>From 978427c2dcf6a4cd1b6a5ef7eed51e1b475fa14a 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) >--- > 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, ["<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/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 %] > <!-- 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 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 %] > <!-- 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/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.17.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
|
177537
|
177538
|
177539
|
177540
|
177541
|
177542
|
177543
|
177544
|
177545
|
177546
|
177547
|
177548
|
177657
|
178822
|
178823
|
178824
|
178825
|
178826
|
178827
|
178828
|
178829
|
178830
|
178831
|
178832
|
178833
|
179868
|
179869
|
179870
|
179871
|
179872
|
179873
|
179874
|
179875
|
179876
|
179877
|
179878
|
179879