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 (-2 / +27 lines)
Lines 192-198 subtest 'build_authorities_query_compat() tests' => sub { Link Here
192
};
192
};
193
193
194
subtest 'build_query tests' => sub {
194
subtest 'build_query tests' => sub {
195
    plan tests => 40;
195
    plan tests => 41;
196
196
197
    my $qb;
197
    my $qb;
198
198
Lines 214-224 subtest 'build_query tests' => sub { Link Here
214
            'title__sort.phrase' => {
214
            'title__sort.phrase' => {
215
                    'order' => 'asc'
215
                    'order' => 'asc'
216
                }
216
                }
217
            },
218
            {
219
            'local-number.raw' => {
220
                    'order' => 'desc'
221
                }
217
            }
222
            }
218
        ],
223
        ],
219
        "sort parameter properly formed"
224
        "sort parameter properly formed"
220
    );
225
    );
221
226
227
    $query = $qb->build_query('test', () );
228
229
    is_deeply(
230
        $query->{sort},
231
        [
232
            {
233
            '_score' => {
234
                    'order' => 'desc'
235
                }
236
            },
237
            {
238
            'local-number.raw' => {
239
                    'order' => 'desc'
240
                }
241
            }
242
        ],
243
        "sort parameter properly formed if no sort passed"
244
    );
245
246
247
222
    t::lib::Mocks::mock_preference('FacetMaxCount','37');
248
    t::lib::Mocks::mock_preference('FacetMaxCount','37');
223
    $query = $qb->build_query('test', %options);
249
    $query = $qb->build_query('test', %options);
224
    ok( defined $query->{aggregations}{ccode}{terms}{size},'we need to ask for a size or we get only 5 facet' );
250
    ok( defined $query->{aggregations}{ccode}{terms}{size},'we need to ask for a size or we get only 5 facet' );
225
- 

Return to bug 23875