|
61 | 61 | use MongoDB\Operation\ReplaceOne;
|
62 | 62 | use MongoDB\Operation\UpdateMany;
|
63 | 63 | use MongoDB\Operation\UpdateOne;
|
| 64 | +use MongoDB\Operation\UpdateSearchIndex; |
64 | 65 | use MongoDB\Operation\Watch;
|
65 | 66 |
|
66 | 67 | use function array_diff_key;
|
@@ -381,45 +382,50 @@ public function createIndexes(array $indexes, array $options = [])
|
381 | 382 | }
|
382 | 383 |
|
383 | 384 | /**
|
384 |
| - * @param string $name |
385 |
| - * @param array|object $definition |
386 |
| - * @param array $options |
| 385 | + * Create an Atlas Search index for the collection. |
| 386 | + * |
| 387 | + * @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/ |
| 388 | + * @see https://mongodb.com/docs/manual/reference/method/db.collection.createSearchIndex/ |
| 389 | + * @param string $name List of search index specifications |
| 390 | + * @param array $definition Atlas Search index definition |
| 391 | + * @param array $options Command options |
387 | 392 | * @return string The name of the created search index
|
| 393 | + * @throws UnsupportedException if options are not supported by the selected server |
| 394 | + * @throws InvalidArgumentException for parameter/option parsing errors |
| 395 | + * @throws DriverRuntimeException for other driver errors (e.g. connection errors) |
388 | 396 | */
|
389 |
| - public function createSearchIndex(string $name, $definition, array $options = []): string |
| 397 | + public function createSearchIndex(string $name, array $definition, array $options): string |
390 | 398 | {
|
391 |
| - $server = select_server($this->manager, $options); |
392 |
| - |
393 |
| - if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { |
394 |
| - $options['writeConcern'] = $this->writeConcern; |
395 |
| - } |
396 |
| - |
397 |
| - $indexes = [ |
398 |
| - [ |
399 |
| - 'name' => $name, |
400 |
| - 'definition' => $definition, |
401 |
| - ], |
402 |
| - ]; |
| 399 | + $names = $this->createSearchIndexes([['name' => $name, 'definition' => $definition]], $options); |
403 | 400 |
|
404 |
| - $operation = new CreateSearchIndexes($this->databaseName, $this->collectionName, $indexes, $options); |
405 |
| - |
406 |
| - return current($operation->execute($server)); |
| 401 | + return current($names); |
407 | 402 | }
|
408 | 403 |
|
409 | 404 | /**
|
410 |
| - * @param array $indexes |
411 |
| - * @param array $options |
412 |
| - * @return string[] |
| 405 | + * Create one or more Atlas Search indexes for the collection. |
| 406 | + * |
| 407 | + * Each element in the $indexes array must have a "name" and a "definition" document. |
| 408 | + * For example: |
| 409 | + * |
| 410 | + * $indexes = [ |
| 411 | + * // Create a search index on all fields |
| 412 | + * [ 'name' => 'search_all', 'definition' => [ 'mappings' => [ 'dynamic' => true ] ] ], |
| 413 | + * ]; |
| 414 | + * |
| 415 | + * @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/ |
| 416 | + * @see https://mongodb.com/docs/manual/reference/method/db.collection.createSearchIndex/ |
| 417 | + * @param array[] $indexes List of search index specifications |
| 418 | + * @param array $options Command options |
| 419 | + * @return string[] The names of the created search indexes |
| 420 | + * @throws UnsupportedException if options are not supported by the selected server |
| 421 | + * @throws InvalidArgumentException for parameter/option parsing errors |
| 422 | + * @throws DriverRuntimeException for other driver errors (e.g. connection errors) |
413 | 423 | */
|
414 | 424 | public function createSearchIndexes(array $indexes, array $options = []): array
|
415 | 425 | {
|
416 | 426 | $server = select_server($this->manager, $options);
|
417 | 427 |
|
418 |
| - if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { |
419 |
| - $options['writeConcern'] = $this->writeConcern; |
420 |
| - } |
421 |
| - |
422 |
| - $operation = new CreateSearchIndexes($this->databaseName, $this->collectionName, $indexes, $options); |
| 428 | + $operation = new CreateSearchIndexes($this->databaseName, $this->collectionName, $indexes); |
423 | 429 |
|
424 | 430 | return $operation->execute($server);
|
425 | 431 | }
|
@@ -602,24 +608,21 @@ public function dropIndexes(array $options = [])
|
602 | 608 | }
|
603 | 609 |
|
604 | 610 | /**
|
605 |
| - * Drop a single search index in the collection. |
| 611 | + * Drop a single Atlas Search index in the collection. |
606 | 612 | *
|
607 |
| - * @param string|IndexInfo $indexName Index name or model object |
608 |
| - * @param array $options Additional options |
609 |
| - * @return array|object Command result document |
| 613 | + * @param string $name Search index name |
| 614 | + * @param array $options Additional options |
610 | 615 | * @throws UnsupportedException if options are not supported by the selected server
|
611 | 616 | * @throws InvalidArgumentException for parameter/option parsing errors
|
612 | 617 | * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
|
613 | 618 | */
|
614 |
| - public function dropSearchIndex(string $indexName, array $options = []) |
| 619 | + public function dropSearchIndex(string $name, array $options = []): void |
615 | 620 | {
|
616 |
| - $indexName = (string) $indexName; |
617 |
| - |
618 | 621 | $server = select_server($this->manager, $options);
|
619 | 622 |
|
620 |
| - $operation = new DropSearchIndex($this->databaseName, $this->collectionName, $indexName); |
| 623 | + $operation = new DropSearchIndex($this->databaseName, $this->collectionName, $name); |
621 | 624 |
|
622 |
| - return $operation->execute($server); |
| 625 | + $operation->execute($server); |
623 | 626 | }
|
624 | 627 |
|
625 | 628 | /**
|
@@ -1172,6 +1175,24 @@ public function updateOne($filter, $update, array $options = [])
|
1172 | 1175 | return $operation->execute($server);
|
1173 | 1176 | }
|
1174 | 1177 |
|
| 1178 | + /** |
| 1179 | + * Update a single Atlas Search index in the collection. |
| 1180 | + * |
| 1181 | + * @param string $name Search index name |
| 1182 | + * @param array $definition Atlas Search index definition |
| 1183 | + * @param array $options Command options |
| 1184 | + * @throws UnsupportedException if options are not supported by the selected server |
| 1185 | + * @throws InvalidArgumentException for parameter parsing errors |
| 1186 | + * @throws DriverRuntimeException for other driver errors (e.g. connection errors) |
| 1187 | + */ |
| 1188 | + public function updateSearchIndex(string $name, array $definition, array $options = []): void |
| 1189 | + { |
| 1190 | + $operation = new UpdateSearchIndex($this->databaseName, $this->collectionName, $name, $definition, $options); |
| 1191 | + $server = select_server($this->manager, $options); |
| 1192 | + |
| 1193 | + $operation->execute($server); |
| 1194 | + } |
| 1195 | + |
1175 | 1196 | /**
|
1176 | 1197 | * Create a change stream for watching changes to the collection.
|
1177 | 1198 | *
|
|
0 commit comments