Skip to content

Commit 49937a6

Browse files
committed
Merge option arrays for listSearchIndexes
1 parent ff95541 commit 49937a6

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

src/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,22 +1015,22 @@ public function listIndexes(array $options = [])
10151015
}
10161016

10171017
/**
1018-
* Returns information for all indexes for the collection.
1018+
* Returns information for all Atlas Search indexes for the collection.
10191019
*
10201020
* @see ListSearchIndexes::__construct() for supported aggregation and list options
10211021
* @return Traversable
10221022
* @throws InvalidArgumentException for parameter/option parsing errors
10231023
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
10241024
*/
1025-
public function listSearchIndexes(string $name, array $aggregationOptions = [], array $listIndexOptions = []): Traversable
1025+
public function listSearchIndexes(string $name, array $options = []): Traversable
10261026
{
10271027
$filter = [];
10281028
if ($name) {
10291029
$filter += ['name' => $name];
10301030
}
10311031

1032-
$operation = new ListSearchIndexes($this->databaseName, $this->collectionName, $filter, $aggregationOptions + $listIndexOptions);
1033-
$server = select_server($this->manager, $listIndexOptions);
1032+
$operation = new ListSearchIndexes($this->databaseName, $this->collectionName, $filter, $options);
1033+
$server = select_server($this->manager, $options);
10341034

10351035
return $operation->execute($server);
10361036
}

src/Operation/ListSearchIndexes.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
namespace MongoDB\Operation;
1919

20+
use ArrayIterator;
2021
use MongoDB\Driver\Cursor;
2122
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
2223
use MongoDB\Driver\Server;
2324
use MongoDB\Exception\InvalidArgumentException;
2425
use MongoDB\Exception\UnexpectedValueException;
2526
use MongoDB\Exception\UnsupportedException;
2627

27-
use function array_intersect_key;
2828
use function is_array;
29-
use function is_integer;
3029
use function is_object;
30+
use function is_string;
31+
use function MongoDB\document_to_array;
3132

3233
/**
3334
* Operation for the listSearchIndexes command.
@@ -49,9 +50,6 @@ class ListSearchIndexes implements Executable
4950
/** @var array */
5051
private $aggregateOptions;
5152

52-
/** @var array */
53-
private $listIndexesOptions;
54-
5553
/** @var Aggregate */
5654
private $aggregate;
5755

@@ -64,26 +62,25 @@ class ListSearchIndexes implements Executable
6462
* @param array $options Command options
6563
* @throws InvalidArgumentException for parameter/option parsing errors
6664
*/
67-
public function __construct(string $databaseName, string $collectionName, array $filter, array $options = [])
65+
public function __construct(string $databaseName, string $collectionName, $filter, array $options = [])
6866
{
6967
if (! is_array($filter) && ! is_object($filter)) {
7068
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
7169
}
7270

73-
if (isset($options['limit']) && ! is_integer($options['limit'])) {
74-
throw InvalidArgumentException::invalidType('"limit" option', $options['limit'], 'integer');
75-
}
71+
$filter = document_to_array($filter);
7672

77-
if (isset($options['skip']) && ! is_integer($options['skip'])) {
78-
throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer');
73+
if (isset($filter['name']) && ! is_string($options['name'])) {
74+
throw InvalidArgumentException::invalidType('"name" filter', $filter['name'], 'string');
7975
}
8076

8177
$this->databaseName = $databaseName;
8278
$this->collectionName = $collectionName;
8379
$this->filter = $filter;
8480

85-
$this->aggregateOptions = array_intersect_key($options, ['batchSize' => 1]);
86-
$this->listIndexesOptions = array_intersect_key($options, ['limit' => 1, 'skip' => 1]);
81+
/* There is currently no additional options for the $listSearchIndexes operation, the $options array can be
82+
* split into two parts: $listIndexesOptions and $aggregateOptions if options are added in the future. */
83+
$this->aggregateOptions = $options;
8784

8885
$this->aggregate = $this->createAggregate();
8986
}
@@ -92,11 +89,12 @@ public function __construct(string $databaseName, string $collectionName, array
9289
* Execute the operation.
9390
*
9491
* @see Executable::execute()
92+
* @return ArrayIterator|Cursor
9593
* @throws UnexpectedValueException if the command response was malformed
9694
* @throws UnsupportedException if collation or read concern is used and unsupported
9795
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
9896
*/
99-
public function execute(Server $server): Cursor
97+
public function execute(Server $server)
10098
{
10199
return $this->aggregate->execute($server);
102100
}
@@ -107,14 +105,6 @@ private function createAggregate(): Aggregate
107105
['$listSearchIndexes' => (object) $this->filter],
108106
];
109107

110-
if (isset($this->listIndexesOptions['skip'])) {
111-
$pipeline[] = ['$skip' => $this->listIndexesOptions['skip']];
112-
}
113-
114-
if (isset($this->listIndexesOptions['limit'])) {
115-
$pipeline[] = ['$limit' => $this->listIndexesOptions['limit']];
116-
}
117-
118108
return new Aggregate($this->databaseName, $this->collectionName, $pipeline, $this->aggregateOptions);
119109
}
120110
}

0 commit comments

Comments
 (0)