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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-11 / +52 lines)
Lines 45-50 use JSON; Link Here
45
use List::MoreUtils qw/ each_array /;
45
use List::MoreUtils qw/ each_array /;
46
use Modern::Perl;
46
use Modern::Perl;
47
use URI::Escape;
47
use URI::Escape;
48
use URI::QueryParam;
48
49
49
use C4::Context;
50
use C4::Context;
50
use Koha::Exceptions;
51
use Koha::Exceptions;
Lines 196-204 reproduce this search, and C<$query_desc> set to something else. Link Here
196
=cut
197
=cut
197
198
198
sub build_query_compat {
199
sub build_query_compat {
199
    my ( $self, $operators, $operands, $indexes, $orig_limits, $sort_by, $scan,
200
    my (
200
        $lang, $params )
201
        $self,
201
      = @_;
202
        $operators,
203
        $operands,
204
        $indexes,
205
        $orig_limits,
206
        $sort_by,
207
        $scan,
208
        $lang,
209
        $params
210
    ) = @_;
211
212
    # TODO: $params?
213
    my $query_cgi = $self->_build_query_query_string(
214
        {
215
            'operators' => $operators,
216
            'operands' => $operands,
217
            'indexes' => $indexes,
218
            'sort_by' => $sort_by
219
        }
220
    );
221
    my $limit_cgi = $orig_limits && @{$orig_limits} ?
222
        "&" . $self->_build_limit_query_string({ 'limits' => $orig_limits }) : '';
202
223
203
#die Dumper ( $self, $operators, $operands, $indexes, $orig_limits, $sort_by, $scan, $lang );
224
#die Dumper ( $self, $operators, $operands, $indexes, $orig_limits, $sort_by, $scan, $lang );
204
    my @sort_params  = $self->_convert_sort_fields(@$sort_by);
225
    my @sort_params  = $self->_convert_sort_fields(@$sort_by);
Lines 235-251 sub build_query_compat { Link Here
235
    $options{expanded_facet} = $params->{expanded_facet};
256
    $options{expanded_facet} = $params->{expanded_facet};
236
    my $query = $self->build_query( $query_str, %options );
257
    my $query = $self->build_query( $query_str, %options );
237
258
238
    #die Dumper($query);
239
    # We roughly emulate the CGI parameters of the zebra query builder
240
    my $query_cgi;
241
    $query_cgi = 'idx=kw&q=' . uri_escape_utf8( $operands->[0] ) if @$operands;
242
    my $simple_query;
259
    my $simple_query;
243
    $simple_query = $operands->[0] if @$operands == 1;
260
    $simple_query = $operands->[0] if @$operands == 1;
244
    my $query_desc   = $simple_query;
261
    my $query_desc   = $simple_query;
245
    my $limit        = $self->_join_queries( $self->_convert_index_strings(@$limits));
262
    my $limit        = $self->_join_queries( $self->_convert_index_strings(@$limits));
246
    my $limit_cgi = ( $orig_limits and @$orig_limits )
263
247
      ? '&limit=' . join( '&limit=', map { uri_escape_utf8($_) } @$orig_limits )
248
      : '';
249
    my $limit_desc;
264
    my $limit_desc;
250
    $limit_desc = "$limit" if $limit;
265
    $limit_desc = "$limit" if $limit;
251
    return (
266
    return (
Lines 254-259 sub build_query_compat { Link Here
254
    );
269
    );
255
}
270
}
256
271
272
sub _build_query_query_string {
273
    my ( $self, $query_parts ) = @_;
274
    my $uri = URI->new("", "http");
275
    my $next = each_array(
276
        @{$query_parts->{operands}},
277
        @{$query_parts->{operators}},
278
        @{$query_parts->{indexes}}
279
    );
280
    while (my ($operand, $operator, $index) = $next->()) {
281
        last if !$operand; # TODO: Is this sane???
282
        $uri->query_param_append('idx' => $index) if $index;
283
        $uri->query_param_append('q' => $operand) if $operand;
284
        $uri->query_param_append('op' => $operator) if $operator;
285
    }
286
    if ($query_parts->{sort_by}) {
287
        $uri->query_param('sort_by' => $query_parts->{sort_by});
288
    }
289
    return $uri->query;
290
}
291
292
sub _build_limit_query_string {
293
    my ($self, $query_parts) = @_;
294
    my $uri = URI->new("", "http");
295
    $uri->query_param('limit' => $query_parts->{limits});
296
    return $uri->query;
297
}
298
257
=head2 build_authorities_query
299
=head2 build_authorities_query
258
300
259
    my $query = $builder->build_authorities_query(\%search);
301
    my $query = $builder->build_authorities_query(\%search);
260
- 

Return to bug 20114