|
24 | 24 | use MongoDB\BSON\Regex;
|
25 | 25 | use MongoDB\BSON\UTCDateTime;
|
26 | 26 | use MongoDB\Builder\Stage\FluentFactoryTrait;
|
| 27 | +use MongoDB\Builder\Type\SearchOperatorInterface; |
27 | 28 | use MongoDB\Driver\Cursor;
|
28 | 29 | use Override;
|
29 | 30 | use RuntimeException;
|
30 | 31 | use stdClass;
|
31 | 32 |
|
32 | 33 | use function array_fill_keys;
|
| 34 | +use function array_filter; |
33 | 35 | use function array_is_list;
|
34 | 36 | use function array_key_exists;
|
35 | 37 | use function array_map;
|
@@ -1490,6 +1492,42 @@ public function options(array $options)
|
1490 | 1492 | return $this;
|
1491 | 1493 | }
|
1492 | 1494 |
|
| 1495 | + /** |
| 1496 | + * Performs a full-text search of the field or fields in an Atlas collection. |
| 1497 | + * NOTE: $search is only available for MongoDB Atlas clusters, and is not available for self-managed deployments. |
| 1498 | + * |
| 1499 | + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/ |
| 1500 | + * |
| 1501 | + * @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. |
| 1502 | + * @param ?string $index Name of the Atlas Search index to use. If omitted, defaults to "default". |
| 1503 | + * @param ?array $highlight Specifies the highlighting options for displaying search terms in their original context. |
| 1504 | + * @param ?bool $concurrent Parallelize search across segments on dedicated search nodes. |
| 1505 | + * @param ?string $count Document that specifies the count options for retrieving a count of the results. |
| 1506 | + * @param ?string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. |
| 1507 | + * @param ?string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. |
| 1508 | + * @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. |
| 1509 | + * @param ?array $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. |
| 1510 | + * @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. |
| 1511 | + * @param ?array $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. |
| 1512 | + */ |
| 1513 | + public function search( |
| 1514 | + SearchOperatorInterface|array $operator, |
| 1515 | + ?string $index = null, |
| 1516 | + ?array $highlight = null, |
| 1517 | + ?bool $concurrent = null, |
| 1518 | + ?string $count = null, |
| 1519 | + ?string $searchAfter = null, |
| 1520 | + ?string $searchBefore = null, |
| 1521 | + ?bool $scoreDetails = null, |
| 1522 | + ?array $sort = null, |
| 1523 | + ?bool $returnStoredSource = null, |
| 1524 | + ?array $tracking = null, |
| 1525 | + ): Collection|LazyCollection { |
| 1526 | + return $this->aggregate() |
| 1527 | + ->search(...array_filter(func_get_args(), fn ($arg) => $arg !== null)) |
| 1528 | + ->get(); |
| 1529 | + } |
| 1530 | + |
1493 | 1531 | /**
|
1494 | 1532 | * Apply the connection's session to options if it's not already specified.
|
1495 | 1533 | */
|
|
0 commit comments