View | Details | Raw Unified | Return to bug 27113
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/Browse.pm (-4 / +65 lines)
Lines 40-46 Koha::SearchEngine::ElasticSearch::Browse - browse functions for Elasticsearch Link Here
40
40
41
This provides an easy interface to the "browse" functionality. Essentially,
41
This provides an easy interface to the "browse" functionality. Essentially,
42
it does a fast prefix search on defined fields. The fields have to be marked
42
it does a fast prefix search on defined fields. The fields have to be marked
43
as "suggestible" in the database when indexing takes place.
43
as "suggestible" in the database when indexing takes place(no action required for autocomplete).
44
44
45
=head1 METHODS
45
=head1 METHODS
46
46
Lines 162-174 sub _build_query { Link Here
162
    return $query;
162
    return $query;
163
}
163
}
164
164
165
=head2 autocomplete_one_idx
166
167
    my $query = $self->autocomplete_one_idx($cgi_q, $prefix, $analyzer, $token_counter);
168
169
Does a prefix search for C<$prefix> (only one prefix), looking for C<$cgi_q> , using analyzer C<$analyzer> ,
170
C<$token_counter> is used for identify which word to use in autocomplete
171
172
=cut
173
174
=head3 Returns
175
176
This returns an arrayref of hashrefs with highlights. Each hashref contains a "text" element that contains the field as returned.
177
178
=cut
179
165
sub autocomplete_one_idx {
180
sub autocomplete_one_idx {
166
    my ($self, $cgi_q, $prefix, $analyzer, $token_counter) = @_;
181
    my ($self, $cgi_q, $prefix, $analyzer, $token_counter) = @_;
167
    my @source;
182
    my @source;
168
    my $elasticsearch = $self->get_elasticsearch();
183
    my $elasticsearch = $self->get_elasticsearch();
169
    # we can change these variables
170
    my ($nb_fragments, $size_fragment, $pre_tags, $post_tags) = (1, 100, ["<strong>"], ["</strong>"]);
171
172
    my $query = $self->_build_query_autocomplete($cgi_q, $prefix, $analyzer);
184
    my $query = $self->_build_query_autocomplete($cgi_q, $prefix, $analyzer);
173
    my $res = $elasticsearch->search(
185
    my $res = $elasticsearch->search(
174
        index => $self->index_name,
186
        index => $self->index_name,
Lines 181-186 sub autocomplete_one_idx { Link Here
181
  return $res;
193
  return $res;
182
}
194
}
183
195
196
=head2 autocomplete_idx
197
198
    my $query = $self->autocomplete_idx($cgi_q, $prefix, $analyzer, $token_counter);
199
200
Does a prefix search for C<$prefix> (many prefix), looking for C<$cgi_q>, using analyzer C<$analyzer>,
201
C<$token_counter> is used for identify which word to use in autocomplete
202
203
=cut
204
205
=head3 Returns
206
207
This returns an arrayref for all prefix of hashrefs with highlights. Each hashref contains a "text" element
208
that contains the field as returned.
209
210
=cut
211
184
sub autocomplete_idx {
212
sub autocomplete_idx {
185
  my ($self, $cgi_q, $prefix, $analyzer, $token_counter) = @_;
213
  my ($self, $cgi_q, $prefix, $analyzer, $token_counter) = @_;
186
  my %results;
214
  my %results;
Lines 195-200 sub autocomplete_idx { Link Here
195
  return \%results;
223
  return \%results;
196
}
224
}
197
225
226
=head2 _build_query_autocomplete
227
228
    my $query = $self->_build_query_autocomplete($cgi_q, $prefix, $analyzer);
229
230
Arguments:
231
232
=over 4
233
234
=item cgi_q
235
236
GET request
237
238
=item prefix
239
240
Field(s) for autocomplete (title, author, etc...)
241
242
=item analyzer
243
244
Name of analyzer wich we use for autocomplete
245
246
=back
247
248
=cut
249
250
=head3 Returns
251
252
This returns an arrayref for all prefix of hashrefs with highlights. Each hashref contains a "text" element
253
that contains the field as returned.
254
255
=cut
256
198
sub _build_query_autocomplete {
257
sub _build_query_autocomplete {
199
    my ($self, $cgi_q, $prefix, $analyzer) = @_;
258
    my ($self, $cgi_q, $prefix, $analyzer) = @_;
200
    my (@source);
259
    my (@source);
Lines 236-241 __END__ Link Here
236
295
237
=item Robin Sheat << <robin@catalyst.net.nz> >>
296
=item Robin Sheat << <robin@catalyst.net.nz> >>
238
297
298
=item Ivan Dziuba << <ivan.dziuba@inlibro.com> >>
299
239
=back
300
=back
240
301
241
=cut
302
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc (-1 / +1 lines)
Lines 146-151 Link Here
146
[% END %]
146
[% END %]
147
<!-- Intranet inc JS IntranetAutocompleteElasticSearch -->
147
<!-- Intranet inc JS IntranetAutocompleteElasticSearch -->
148
[% IF ( Koha.Preference('IntranetAutocompleteElasticSearch') ) %]
148
[% IF ( Koha.Preference('IntranetAutocompleteElasticSearch') ) %]
149
	[% Asset.js("js/elasticsearch/autocomplete.js") %]
149
[% Asset.js("js/elasticsearch/autocomplete.js") | $raw %]
150
[% END %]
150
[% END %]
151
<!-- / js_includes.inc -->
151
<!-- / js_includes.inc -->
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc (-1 / +1 lines)
Lines 320-326 $(document).ready(function() { Link Here
320
[% PROCESS jsinclude %]
320
[% PROCESS jsinclude %]
321
<!-- OPAC *.inc JS OPACAutocompleteElasticSearch -->
321
<!-- OPAC *.inc JS OPACAutocompleteElasticSearch -->
322
[% IF ( Koha.Preference('OPACAutocompleteElasticSearch') ) %]
322
[% IF ( Koha.Preference('OPACAutocompleteElasticSearch') ) %]
323
    [% Asset.js("js/opac-elasticsearch/opac-autocomplete.js") %]
323
    [% Asset.js("js/opac-elasticsearch/opac-autocomplete.js") | $raw %]
324
[% END %]
324
[% END %]
325
[% IF ( Koha.Preference('OPACUserJS') ) %]
325
[% IF ( Koha.Preference('OPACUserJS') ) %]
326
    <script>
326
    <script>
(-)a/t/Koha_SearchEngine_Elasticsearch_Browse.t (-1 / +30 lines)
Lines 65-68 subtest "_build_query tests" => sub { Link Here
65
    }, 'Fuzziness and size specified');
65
    }, 'Fuzziness and size specified');
66
};
66
};
67
67
68
subtest "_build_query_autocomplete tests" => sub {
69
    plan tests => 1;
70
71
    my $browse = Koha::SearchEngine::Elasticsearch::Browse->new({index=>'dummy'});
72
73
    my $q = $browse->_build_query_autocomplete('a', 'title', 'autocomplete');
74
75
    is_deeply($q, {
76
        _source    => ["title"],
77
        query => {
78
            match => {
79
                "title.autocomplete"  => {
80
                    query => 'a',
81
                    operator => 'and'
82
                }
83
            }
84
        },
85
        highlight => {
86
            number_of_fragments => 1,
87
            fragment_size => 100,
88
            pre_tags => ["<strong>"],
89
            post_tags => ["</strong>"],
90
            fields => {
91
                "title.autocomplete" => {}
92
            }
93
        }
94
    }, 'Autocomplete for title is specified');
95
96
};
97
68
done_testing();
98
done_testing();
69
- 

Return to bug 27113