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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-5 / +18 lines)
Lines 243-261 sub build_query_compat { Link Here
243
    $options{expanded_facet} = $params->{expanded_facet};
243
    $options{expanded_facet} = $params->{expanded_facet};
244
    my $query = $self->build_query( $query_str, %options );
244
    my $query = $self->build_query( $query_str, %options );
245
245
246
    #die Dumper($query);
247
    # We roughly emulate the CGI parameters of the zebra query builder
246
    # We roughly emulate the CGI parameters of the zebra query builder
248
    my $query_cgi;
247
    my $query_cgi = '';
249
    $query_cgi = 'q=' . uri_escape_utf8( $operands->[0] ) if @$operands;
248
    shift @$operators; # Shift out the one we unshifted before
249
    $ea = each_array( @$operands, @$operators, @$indexes );
250
    while ( my ( $oand, $otor, $index ) = $ea->() ) {
251
        $query_cgi .= '&' if $query_cgi;
252
        $query_cgi .= 'idx=' . uri_escape_utf8( $index // '') . '&q=' . uri_escape_utf8( $oand );
253
        $query_cgi .= '&op=' . uri_escape_utf8( $otor ) if $otor;
254
    }
255
    $query_cgi .= '&scan=1' if ( $scan );
256
250
    my $simple_query;
257
    my $simple_query;
251
    $simple_query = $operands->[0] if @$operands == 1;
258
    $simple_query = $operands->[0] if @$operands == 1;
252
    my $query_desc   = $simple_query;
259
    my $query_desc;
253
    my $limit        = $self->_join_queries( $self->_convert_index_strings(@$limits));
260
    if ( $simple_query ) {
261
        $query_desc = $simple_query;
262
    } else {
263
        $query_desc = $query_str;
264
    }
265
    my $limit     = $self->_join_queries( $self->_convert_index_strings(@$limits));
254
    my $limit_cgi = ( $orig_limits and @$orig_limits )
266
    my $limit_cgi = ( $orig_limits and @$orig_limits )
255
      ? '&limit=' . join( '&limit=', map { uri_escape_utf8($_) } @$orig_limits )
267
      ? '&limit=' . join( '&limit=', map { uri_escape_utf8($_) } @$orig_limits )
256
      : '';
268
      : '';
257
    my $limit_desc;
269
    my $limit_desc;
258
    $limit_desc = "$limit" if $limit;
270
    $limit_desc = "$limit" if $limit;
271
259
    return (
272
    return (
260
        undef,  $query,     $simple_query, $query_cgi, $query_desc,
273
        undef,  $query,     $simple_query, $query_cgi, $query_desc,
261
        $limit, $limit_cgi, $limit_desc,   undef,      undef
274
        $limit, $limit_cgi, $limit_desc,   undef,      undef
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-5 / +9 lines)
Lines 169-175 subtest 'build_authorities_query_compat() tests' => sub { Link Here
169
};
169
};
170
170
171
subtest 'build_query tests' => sub {
171
subtest 'build_query tests' => sub {
172
    plan tests => 26;
172
    plan tests => 29;
173
173
174
    my $qb;
174
    my $qb;
175
175
Lines 224-229 subtest 'build_query tests' => sub { Link Here
224
        "query not altered if QueryAutoTruncate disabled"
224
        "query not altered if QueryAutoTruncate disabled"
225
    );
225
    );
226
226
227
    my ($simple_query, $query_cgi, $query_desc);
228
    ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( undef, ['"donald duck"', 'walt disney'], ['ti', 'au'] );
229
    is($query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query');
230
    is($query_desc, '(title:"donald duck") (author:walt disney)', 'query desc ok for multiterm query');
231
227
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
232
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
228
233
229
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
234
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
Lines 334-347 subtest 'build_query tests' => sub { Link Here
334
        "query of specific field is added AND suppress:0"
339
        "query of specific field is added AND suppress:0"
335
    );
340
    );
336
341
337
    my ($simple_query, $query_cgi);
342
    ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } );
338
    ( undef, $query, $simple_query, $query_cgi ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } );
339
    is(
343
    is(
340
        $query->{query}{query_string}{query},
344
        $query->{query}{query_string}{query},
341
        '(title:"donald duck")',
345
        '(title:"donald duck")',
342
        "query of specific field is not added AND suppress:0"
346
        "query of specific field is not added AND suppress:0"
343
    );
347
    );
344
    is($query_cgi, 'q=title%3A%22donald%20duck%22', 'query cgi');
348
    is($query_cgi, 'idx=&q=title%3A%22donald%20duck%22', 'query cgi');
349
    is($query_desc, 'title:"donald duck"', 'query desc ok');
345
};
350
};
346
351
347
352
348
- 

Return to bug 22413