Skip to content

Commit 0f253d5

Browse files
committed
Add tests for sorting Scout results by relevance score
1 parent 8532c77 commit 0f253d5

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/Scout/ScoutEngineTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,44 @@ function () {
404404
],
405405
]),
406406
];
407+
408+
yield 'ordered by score' => [
409+
function () {
410+
$builder = new Builder(new SearchableModel(), 'lar');
411+
$builder->orderBy('_score', 'desc');
412+
413+
return $builder;
414+
},
415+
array_replace_recursive($defaultPipeline, [
416+
[
417+
'$search' => [
418+
'sort' => [
419+
'score' => ['$meta' => 'searchScore'],
420+
],
421+
],
422+
],
423+
]),
424+
];
425+
426+
yield 'ordered by score and field' => [
427+
function () {
428+
$builder = new Builder(new SearchableModel(), 'lar');
429+
$builder->orderBy('_score', 'desc');
430+
$builder->orderBy('name', 'asc');
431+
432+
return $builder;
433+
},
434+
array_replace_recursive($defaultPipeline, [
435+
[
436+
'$search' => [
437+
'sort' => [
438+
'score' => ['$meta' => 'searchScore'],
439+
'name' => 1,
440+
],
441+
],
442+
],
443+
]),
444+
];
407445
}
408446

409447
public function testPaginate()

0 commit comments

Comments
 (0)