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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-6 / +20 lines)
Lines 227-234 sub build_query_compat { Link Here
227
    # would be to pass them separately into build_query and let it build
227
    # would be to pass them separately into build_query and let it build
228
    # them into a structured ES query itself. Maybe later, though that'd be
228
    # them into a structured ES query itself. Maybe later, though that'd be
229
    # more robust.
229
    # more robust.
230
    my $search_param_query_str = join( ' ', $self->_create_query_string(@search_params) );
230
    my $query_str = join( ' AND ',
231
    my $query_str = join( ' AND ',
231
        join( ' ', $self->_create_query_string(@search_params) ) || (),
232
        $search_param_query_str || (),
232
        $self->_join_queries( $self->_convert_index_strings(@$limits) ) || () );
233
        $self->_join_queries( $self->_convert_index_strings(@$limits) ) || () );
233
234
234
    my @fields = '_all';
235
    my @fields = '_all';
Lines 244-262 sub build_query_compat { Link Here
244
    $options{expanded_facet} = $params->{expanded_facet};
245
    $options{expanded_facet} = $params->{expanded_facet};
245
    my $query = $self->build_query( $query_str, %options );
246
    my $query = $self->build_query( $query_str, %options );
246
247
247
    #die Dumper($query);
248
    # We roughly emulate the CGI parameters of the zebra query builder
248
    # We roughly emulate the CGI parameters of the zebra query builder
249
    my $query_cgi;
249
    my $query_cgi = '';
250
    $query_cgi = 'q=' . uri_escape_utf8( $operands->[0] ) if @$operands;
250
    shift @$operators; # Shift out the one we unshifted before
251
    $ea = each_array( @$operands, @$operators, @$indexes );
252
    while ( my ( $oand, $otor, $index ) = $ea->() ) {
253
        $query_cgi .= '&' if $query_cgi;
254
        $query_cgi .= 'idx=' . uri_escape_utf8( $index // '') . '&q=' . uri_escape_utf8( $oand );
255
        $query_cgi .= '&op=' . uri_escape_utf8( $otor ) if $otor;
256
    }
257
    $query_cgi .= '&scan=1' if ( $scan );
258
251
    my $simple_query;
259
    my $simple_query;
252
    $simple_query = $operands->[0] if @$operands == 1;
260
    $simple_query = $operands->[0] if @$operands == 1;
253
    my $query_desc   = $simple_query;
261
    my $query_desc;
254
    my $limit        = $self->_join_queries( $self->_convert_index_strings(@$limits));
262
    if ( $simple_query ) {
263
        $query_desc = $simple_query;
264
    } else {
265
        $query_desc = $search_param_query_str;
266
    }
267
    my $limit     = $self->_join_queries( $self->_convert_index_strings(@$limits));
255
    my $limit_cgi = ( $orig_limits and @$orig_limits )
268
    my $limit_cgi = ( $orig_limits and @$orig_limits )
256
      ? '&limit=' . join( '&limit=', map { uri_escape_utf8($_) } @$orig_limits )
269
      ? '&limit=' . join( '&limit=', map { uri_escape_utf8($_) } @$orig_limits )
257
      : '';
270
      : '';
258
    my $limit_desc;
271
    my $limit_desc;
259
    $limit_desc = "$limit" if $limit;
272
    $limit_desc = "$limit" if $limit;
273
260
    return (
274
    return (
261
        undef,  $query,     $simple_query, $query_cgi, $query_desc,
275
        undef,  $query,     $simple_query, $query_cgi, $query_desc,
262
        $limit, $limit_cgi, $limit_desc,   undef,      undef
276
        $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 => 30;
172
    plan tests => 33;
173
173
174
    my $qb;
174
    my $qb;
175
175
Lines 238-243 subtest 'build_query tests' => sub { Link Here
238
        'multiple query terms are enclosed in parenthesis while a single one is not'
238
        'multiple query terms are enclosed in parenthesis while a single one is not'
239
    );
239
    );
240
240
241
    my ($simple_query, $query_cgi, $query_desc);
242
    ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( undef, ['"donald duck"', 'walt disney'], ['ti', 'au'] );
243
    is($query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query');
244
    is($query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query');
245
241
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
246
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
242
247
243
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
248
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
Lines 362-375 subtest 'build_query tests' => sub { Link Here
362
        "query of specific field is added AND suppress:0"
367
        "query of specific field is added AND suppress:0"
363
    );
368
    );
364
369
365
    my ($simple_query, $query_cgi);
370
    ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } );
366
    ( undef, $query, $simple_query, $query_cgi ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } );
367
    is(
371
    is(
368
        $query->{query}{query_string}{query},
372
        $query->{query}{query_string}{query},
369
        '(title:"donald duck")',
373
        '(title:"donald duck")',
370
        "query of specific field is not added AND suppress:0"
374
        "query of specific field is not added AND suppress:0"
371
    );
375
    );
372
    is($query_cgi, 'q=title%3A%22donald%20duck%22', 'query cgi');
376
    is($query_cgi, 'idx=&q=title%3A%22donald%20duck%22', 'query cgi');
377
    is($query_desc, 'title:"donald duck"', 'query desc ok');
373
};
378
};
374
379
375
380
376
- 

Return to bug 22413