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