Skip to content

Commit ea0b7b0

Browse files
committed
Add Builder::search
1 parent a257a9f commit ea0b7b0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Query/Builder.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
use MongoDB\BSON\Regex;
2525
use MongoDB\BSON\UTCDateTime;
2626
use MongoDB\Builder\Stage\FluentFactoryTrait;
27+
use MongoDB\Builder\Type\SearchOperatorInterface;
2728
use MongoDB\Driver\Cursor;
2829
use Override;
2930
use RuntimeException;
3031
use stdClass;
3132

3233
use function array_fill_keys;
34+
use function array_filter;
3335
use function array_is_list;
3436
use function array_key_exists;
3537
use function array_map;
@@ -1490,6 +1492,42 @@ public function options(array $options)
14901492
return $this;
14911493
}
14921494

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+
14931531
/**
14941532
* Apply the connection's session to options if it's not already specified.
14951533
*/

0 commit comments

Comments
 (0)