|
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 | use Traversable;
|
66 | 67 |
|
@@ -394,45 +395,50 @@ public function createIndexes(array $indexes, array $options = [])
|
394 | 395 | }
|
395 | 396 |
|
396 | 397 | /**
|
397 |
| - * @param string $name |
398 |
| - * @param array|object $definition |
399 |
| - * @param array $options |
| 398 | + * Create an Atlas Search index for the collection. |
| 399 | + * |
| 400 | + * @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/ |
| 401 | + * @see https://mongodb.com/docs/manual/reference/method/db.collection.createSearchIndex/ |
| 402 | + * @param string $name List of search index specifications |
| 403 | + * @param array $definition Atlas Search index definition |
| 404 | + * @param array $options Command options |
400 | 405 | * @return string The name of the created search index
|
| 406 | + * @throws UnsupportedException if options are not supported by the selected server |
| 407 | + * @throws InvalidArgumentException for parameter/option parsing errors |
| 408 | + * @throws DriverRuntimeException for other driver errors (e.g. connection errors) |
401 | 409 | */
|
402 |
| - public function createSearchIndex(string $name, $definition, array $options = []): string |
| 410 | + public function createSearchIndex(string $name, array $definition, array $options): string |
403 | 411 | {
|
404 |
| - $server = select_server($this->manager, $options); |
405 |
| - |
406 |
| - if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { |
407 |
| - $options['writeConcern'] = $this->writeConcern; |
408 |
| - } |
409 |
| - |
410 |
| - $indexes = [ |
411 |
| - [ |
412 |
| - 'name' => $name, |
413 |
| - 'definition' => $definition, |
414 |
| - ], |
415 |
| - ]; |
| 412 | + $names = $this->createSearchIndexes([['name' => $name, 'definition' => $definition]], $options); |
416 | 413 |
|
417 |
| - $operation = new CreateSearchIndexes($this->databaseName, $this->collectionName, $indexes, $options); |
418 |
| - |
419 |
| - return current($operation->execute($server)); |
| 414 | + return current($names); |
420 | 415 | }
|
421 | 416 |
|
422 | 417 | /**
|
423 |
| - * @param array $indexes |
424 |
| - * @param array $options |
425 |
| - * @return string[] |
| 418 | + * Create one or more Atlas Search indexes for the collection. |
| 419 | + * |
| 420 | + * Each element in the $indexes array must have a "name" and a "definition" document. |
| 421 | + * For example: |
| 422 | + * |
| 423 | + * $indexes = [ |
| 424 | + * // Create a search index on all fields |
| 425 | + * [ 'name' => 'search_all', 'definition' => [ 'mappings' => [ 'dynamic' => true ] ] ], |
| 426 | + * ]; |
| 427 | + * |
| 428 | + * @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/ |
| 429 | + * @see https://mongodb.com/docs/manual/reference/method/db.collection.createSearchIndex/ |
| 430 | + * @param array[] $indexes List of search index specifications |
| 431 | + * @param array $options Command options |
| 432 | + * @return string[] The names of the created search indexes |
| 433 | + * @throws UnsupportedException if options are not supported by the selected server |
| 434 | + * @throws InvalidArgumentException for parameter/option parsing errors |
| 435 | + * @throws DriverRuntimeException for other driver errors (e.g. connection errors) |
426 | 436 | */
|
427 | 437 | public function createSearchIndexes(array $indexes, array $options = []): array
|
428 | 438 | {
|
429 | 439 | $server = select_server($this->manager, $options);
|
430 | 440 |
|
431 |
| - if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { |
432 |
| - $options['writeConcern'] = $this->writeConcern; |
433 |
| - } |
434 |
| - |
435 |
| - $operation = new CreateSearchIndexes($this->databaseName, $this->collectionName, $indexes, $options); |
| 441 | + $operation = new CreateSearchIndexes($this->databaseName, $this->collectionName, $indexes); |
436 | 442 |
|
437 | 443 | return $operation->execute($server);
|
438 | 444 | }
|
@@ -615,24 +621,21 @@ public function dropIndexes(array $options = [])
|
615 | 621 | }
|
616 | 622 |
|
617 | 623 | /**
|
618 |
| - * Drop a single search index in the collection. |
| 624 | + * Drop a single Atlas Search index in the collection. |
619 | 625 | *
|
620 |
| - * @param string|IndexInfo $indexName Index name or model object |
621 |
| - * @param array $options Additional options |
622 |
| - * @return array|object Command result document |
| 626 | + * @param string $name Search index name |
| 627 | + * @param array $options Additional options |
623 | 628 | * @throws UnsupportedException if options are not supported by the selected server
|
624 | 629 | * @throws InvalidArgumentException for parameter/option parsing errors
|
625 | 630 | * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
|
626 | 631 | */
|
627 |
| - public function dropSearchIndex(string $indexName, array $options = []) |
| 632 | + public function dropSearchIndex(string $name, array $options = []): void |
628 | 633 | {
|
629 |
| - $indexName = (string) $indexName; |
630 |
| - |
631 | 634 | $server = select_server($this->manager, $options);
|
632 | 635 |
|
633 |
| - $operation = new DropSearchIndex($this->databaseName, $this->collectionName, $indexName); |
| 636 | + $operation = new DropSearchIndex($this->databaseName, $this->collectionName, $name); |
634 | 637 |
|
635 |
| - return $operation->execute($server); |
| 638 | + $operation->execute($server); |
636 | 639 | }
|
637 | 640 |
|
638 | 641 | /**
|
@@ -1185,6 +1188,24 @@ public function updateOne($filter, $update, array $options = [])
|
1185 | 1188 | return $operation->execute($server);
|
1186 | 1189 | }
|
1187 | 1190 |
|
| 1191 | + /** |
| 1192 | + * Update a single Atlas Search index in the collection. |
| 1193 | + * |
| 1194 | + * @param string $name Search index name |
| 1195 | + * @param array $definition Atlas Search index definition |
| 1196 | + * @param array $options Command options |
| 1197 | + * @throws UnsupportedException if options are not supported by the selected server |
| 1198 | + * @throws InvalidArgumentException for parameter parsing errors |
| 1199 | + * @throws DriverRuntimeException for other driver errors (e.g. connection errors) |
| 1200 | + */ |
| 1201 | + public function updateSearchIndex(string $name, array $definition, array $options = []): void |
| 1202 | + { |
| 1203 | + $operation = new UpdateSearchIndex($this->databaseName, $this->collectionName, $name, $definition, $options); |
| 1204 | + $server = select_server($this->manager, $options); |
| 1205 | + |
| 1206 | + $operation->execute($server); |
| 1207 | + } |
| 1208 | + |
1188 | 1209 | /**
|
1189 | 1210 | * Create a change stream for watching changes to the collection.
|
1190 | 1211 | *
|
|
0 commit comments