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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (+6 lines)
Lines 114-119 sub build_query { Link Here
114
            push @{ $res->{sort} }, { $f => { order => $d } };
114
            push @{ $res->{sort} }, { $f => { order => $d } };
115
        }
115
        }
116
    }
116
    }
117
    # If not sorting by anything explicitly search by score
118
    if (!defined $res->{sort}){
119
        push @{ $res->{sort} }, { _score => { order => 'desc' } };
120
    }
121
    # Add a tie breaker in case of equally relevant records
122
    push @{ $res->{sort} }, { 'local-number.raw' => { order => 'desc' } };
117
123
118
    # See _convert_facets in Search.pm for how these get turned into
124
    # See _convert_facets in Search.pm for how these get turned into
119
    # things that Koha can use.
125
    # things that Koha can use.
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-3 / +26 lines)
Lines 216-222 subtest 'build_authorities_query_compat() tests' => sub { Link Here
216
};
216
};
217
217
218
subtest 'build_query tests' => sub {
218
subtest 'build_query tests' => sub {
219
    plan tests => 53;
219
    plan tests => 54;
220
220
221
    my $qb;
221
    my $qb;
222
222
Lines 238-248 subtest 'build_query tests' => sub { Link Here
238
            'title__sort' => {
238
            'title__sort' => {
239
                    'order' => 'asc'
239
                    'order' => 'asc'
240
                }
240
                }
241
            }
241
            },
242
            {
243
            'local-number.raw' => {
244
                    'order' => 'desc'
245
                }
246
             }
242
        ],
247
        ],
243
        "sort parameter properly formed"
248
        "sort parameter properly formed"
244
    );
249
    );
245
250
251
    $query = $qb->build_query('test', () );
252
253
    is_deeply(
254
        $query->{sort},
255
        [
256
            {
257
            '_score' => {
258
                    'order' => 'desc'
259
                }
260
            },
261
            {
262
            'local-number.raw' => {
263
                    'order' => 'desc'
264
                }
265
            }
266
        ],
267
        "sort parameter properly formed if no sort passed"
268
    );
269
246
    t::lib::Mocks::mock_preference('FacetMaxCount','37');
270
    t::lib::Mocks::mock_preference('FacetMaxCount','37');
247
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
271
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
248
    $query = $qb->build_query('test', %options);
272
    $query = $qb->build_query('test', %options);
249
- 

Return to bug 23875