Skip to content

Commit ed5c8f7

Browse files
committed
Fix search argument names
1 parent 4d08755 commit ed5c8f7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Query/Builder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,9 @@ public function search(
15241524
?bool $returnStoredSource = null,
15251525
?array $tracking = null,
15261526
): Collection {
1527-
return $this->aggregate()->search(...array_filter(func_get_args(), fn ($arg) => $arg !== null))->get();
1527+
$args = array_filter(compact(['operator', 'index', 'highlight', 'concurrent', 'count', 'searchAfter', 'searchBefore', 'scoreDetails', 'sort', 'returnStoredSource', 'tracking']), fn ($arg) => $arg !== null);
1528+
1529+
return $this->aggregate()->search(...$args)->get();
15281530
}
15291531

15301532
/** @return Collection<string> */

tests/AtlasSearchTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ public function testEloquentBuilderSearch()
154154
], $results->pluck('title')->all());
155155
}
156156

157+
public function testEloquentBuilderWithAdvancedParameters()
158+
{
159+
$results = Book::search(
160+
concurrent: true,
161+
operator: Search::text('title', 'systems'),
162+
sort: ['title' => -1],
163+
);
164+
165+
self::assertInstanceOf(EloquentCollection::class, $results);
166+
self::assertCount(3, $results);
167+
self::assertInstanceOf(Book::class, $results->first());
168+
self::assertSame([
169+
'Operating System Concepts',
170+
'Database System Concepts',
171+
'Modern Operating Systems',
172+
], $results->pluck('title')->all());
173+
}
174+
157175
public function testDatabaseBuilderSearch()
158176
{
159177
$results = $this->getConnection('mongodb')->table('books')

0 commit comments

Comments
 (0)