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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (+7 lines)
Lines 226-231 sub build_query { Link Here
226
            push @{ $res->{sort} }, { $f => { order => $d } };
226
            push @{ $res->{sort} }, { $f => { order => $d } };
227
        }
227
        }
228
    }
228
    }
229
    # If not sorting by anything explicitly search by score
230
    if ( !defined $res->{sort} ) {
231
        push @{ $res->{sort} }, { _score => { order => 'desc' } };
232
    }
233
234
    # Add a tie breaker in case of equally relevant records
235
    push @{ $res->{sort} }, { 'local-number' => { order => 'desc' } };
229
236
230
    unless ( $options{skip_facets} ) {
237
    unless ( $options{skip_facets} ) {
231
238
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-3 / +13 lines)
Lines 228-234 subtest 'build_authorities_query_compat() tests' => sub { Link Here
228
};
228
};
229
229
230
subtest 'build_query tests' => sub {
230
subtest 'build_query tests' => sub {
231
    plan tests => 68;
231
    plan tests => 69;
232
232
233
    my $qb;
233
    my $qb;
234
234
Lines 245-251 subtest 'build_query tests' => sub { Link Here
245
245
246
    is_deeply(
246
    is_deeply(
247
        $query->{sort},
247
        $query->{sort},
248
        [ { 'title__sort' => { 'order' => 'asc' } } ],
248
        [ { 'title__sort' => { 'order' => 'asc' } }, { 'local-number' => { 'order' => 'desc' } } ],
249
        "sort parameter properly formed"
249
        "sort parameter properly formed"
250
    );
250
    );
251
251
Lines 267-272 subtest 'build_query tests' => sub { Link Here
267
    $query = $qb->build_query( 'test', %options );
267
    $query = $qb->build_query( 'test', %options );
268
    ok( !defined $query->{aggregations}, 'Skipping facets means we do not have aggregations in the the query' );
268
    ok( !defined $query->{aggregations}, 'Skipping facets means we do not have aggregations in the the query' );
269
269
270
    $query = $qb->build_query( 'test', () );
271
272
    is_deeply(
273
        $query->{sort},
274
        [
275
            { '_score'       => { 'order' => 'desc' } },
276
            { 'local-number' => { 'order' => 'desc' } }
277
        ],
278
        "sort parameter properly formed if no sort passed"
279
    );
280
270
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '' );
281
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '' );
271
282
272
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
283
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
273
- 

Return to bug 23875