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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (+7 lines)
Lines 223-228 sub build_query { Link Here
223
            push @{ $res->{sort} }, { $f => { order => $d } };
223
            push @{ $res->{sort} }, { $f => { order => $d } };
224
        }
224
        }
225
    }
225
    }
226
    # If not sorting by anything explicitly search by score
227
    if ( !defined $res->{sort} ) {
228
        push @{ $res->{sort} }, { _score => { order => 'desc' } };
229
    }
230
231
    # Add a tie breaker in case of equally relevant records
232
    push @{ $res->{sort} }, { 'local-number' => { order => 'desc' } };
226
233
227
    # See _convert_facets in Search.pm for how these get turned into
234
    # See _convert_facets in Search.pm for how these get turned into
228
    # things that Koha can use.
235
    # things that Koha can use.
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-7 / +14 lines)
Lines 219-225 subtest 'build_authorities_query_compat() tests' => sub { Link Here
219
};
219
};
220
220
221
subtest 'build_query tests' => sub {
221
subtest 'build_query tests' => sub {
222
    plan tests => 61;
222
    plan tests => 62;
223
223
224
    my $qb;
224
    my $qb;
225
225
Lines 237-251 subtest 'build_query tests' => sub { Link Here
237
    is_deeply(
237
    is_deeply(
238
        $query->{sort},
238
        $query->{sort},
239
        [
239
        [
240
            {
240
            { 'title__sort'  => { 'order' => 'asc' } },
241
            'title__sort' => {
241
            { 'local-number' => { 'order' => 'desc' } }
242
                    'order' => 'asc'
243
                }
244
            }
245
        ],
242
        ],
246
        "sort parameter properly formed"
243
        "sort parameter properly formed"
247
    );
244
    );
248
245
246
    $query = $qb->build_query('test', () );
247
248
    is_deeply(
249
        $query->{sort},
250
        [
251
            { '_score'       => { 'order' => 'desc' } },
252
            { 'local-number' => { 'order' => 'desc' } }
253
        ],
254
        "sort parameter properly formed if no sort passed"
255
    );
256
249
    t::lib::Mocks::mock_preference('FacetMaxCount','37');
257
    t::lib::Mocks::mock_preference('FacetMaxCount','37');
250
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
258
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
251
    $query = $qb->build_query('test', %options);
259
    $query = $qb->build_query('test', %options);
252
- 

Return to bug 23875