@@ -361,22 +361,22 @@ public function createIndexes(array $indexes, array $options = [])
361
361
*
362
362
* @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/
363
363
* @see https://mongodb.com/docs/manual/reference/method/db.collection.createSearchIndex/
364
- * @param array|object $definition Atlas Search index mapping definition
365
- * @param array{name?: string, comment ?: mixed } $options Command options
364
+ * @param array|object $definition Atlas Search index mapping definition
365
+ * @param array{comment?: mixed, name?: string, type ?: string } $options Index and command options
366
366
* @return string The name of the created search index
367
367
* @throws UnsupportedException if options are not supported by the selected server
368
368
* @throws InvalidArgumentException for parameter/option parsing errors
369
369
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
370
370
*/
371
371
public function createSearchIndex (array |object $ definition , array $ options = []): string
372
372
{
373
- $ index = ['definition ' => $ definition ];
374
- if ( isset ( $ options [ ' name ' ])) {
375
- $ index [ ' name ' ] = $ options[ ' name ' ] ;
376
- unset( $ options [ ' name ' ]);
377
- }
373
+ $ indexOptionKeys = ['name ' => 1 , ' type ' => 1 ];
374
+ /** @psalm-var array{name?: string, type?: string} */
375
+ $ indexOptions = array_intersect_key ( $ options, $ indexOptionKeys ) ;
376
+ /** @psalm-var array{comment?: mixed} */
377
+ $ operationOptions = array_diff_key ( $ options , $ indexOptionKeys );
378
378
379
- $ names = $ this ->createSearchIndexes ([$ index ] , $ options );
379
+ $ names = $ this ->createSearchIndexes ([[ ' definition ' => $ definition ] + $ indexOptions ] , $ operationOptions );
380
380
381
381
return current ($ names );
382
382
}
@@ -390,16 +390,16 @@ public function createSearchIndex(array|object $definition, array $options = [])
390
390
* For example:
391
391
*
392
392
* $indexes = [
393
- * // Create a search index with the default name, on
393
+ * // Create a search index with the default name on a single field
394
394
* ['definition' => ['mappings' => ['dynamic' => false, 'fields' => ['title' => ['type' => 'string']]]]],
395
395
* // Create a named search index on all fields
396
396
* ['name' => 'search_all', 'definition' => ['mappings' => ['dynamic' => true]]],
397
397
* ];
398
398
*
399
399
* @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/
400
400
* @see https://mongodb.com/docs/manual/reference/method/db.collection.createSearchIndex/
401
- * @param list<array{name?: string, definition: array|object }> $indexes List of search index specifications
402
- * @param array{comment?: string} $options Command options
401
+ * @param list<array{definition: array|object, name?: string, type?: string }> $indexes List of search index specifications
402
+ * @param array{comment?: mixed} $options Command options
403
403
* @return string[] The names of the created search indexes
404
404
* @throws UnsupportedException if options are not supported by the selected server
405
405
* @throws InvalidArgumentException for parameter/option parsing errors
0 commit comments