Skip to content

Commit

Permalink
Fix Eloquent Builder signature
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jan 2, 2025
1 parent 71fd529 commit 905ee37
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use MongoDB\BSON\Document;
use MongoDB\Builder\Type\SearchOperatorInterface;
use MongoDB\Driver\CursorInterface;
use MongoDB\Driver\Exception\WriteException;
use MongoDB\Laravel\Connection;
Expand Down Expand Up @@ -70,9 +71,38 @@ public function aggregate($function = null, $columns = ['*'])
return $result ?: $this;
}

public function search(...$args)
{
$results = $this->toBase()->search(...$args);
/**
* Performs a full-text search of the field or fields in an Atlas collection.
* NOTE: $search is only available for MongoDB Atlas clusters, and is not available for self-managed deployments.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/
*
* @param SearchOperatorInterface|array $operator Operator to search with. You can provide a specific operator or use the compound operator to run a compound query with multiple operators.
* @param ?string $index Name of the Atlas Search index to use. If omitted, defaults to "default".
* @param ?array $highlight Specifies the highlighting options for displaying search terms in their original context.
* @param ?bool $concurrent Parallelize search across segments on dedicated search nodes.
* @param ?string $count Document that specifies the count options for retrieving a count of the results.
* @param ?string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point.
* @param ?string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point.
* @param ?bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false.
* @param ?array $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order.
* @param ?bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search.
* @param ?array $tracking Document that specifies the tracking option to retrieve analytics information on the search terms.
*/
public function search(
SearchOperatorInterface|array $operator,
?string $index = null,
?array $highlight = null,
?bool $concurrent = null,
?string $count = null,
?string $searchAfter = null,
?string $searchBefore = null,
?bool $scoreDetails = null,
?array $sort = null,
?bool $returnStoredSource = null,
?array $tracking = null,
) {
$results = $this->toBase()->search($operator, $index, $highlight, $concurrent, $count, $searchAfter, $searchBefore, $scoreDetails, $sort, $returnStoredSource, $tracking);

return $this->model->hydrate($results->all());
}
Expand Down

0 comments on commit 905ee37

Please sign in to comment.