|
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 |