@@ -371,22 +371,22 @@ public function createIndexes(array $indexes, array $options = [])
371371 *
372372 * @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/
373373 * @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
376376 * @return string The name of the created search index
377377 * @throws UnsupportedException if options are not supported by the selected server
378378 * @throws InvalidArgumentException for parameter/option parsing errors
379379 * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
380380 */
381381 public function createSearchIndex ($ definition , array $ options = []): string
382382 {
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 );
388388
389- $ names = $ this ->createSearchIndexes ([$ index ] , $ options );
389+ $ names = $ this ->createSearchIndexes ([[ ' definition ' => $ definition ] + $ indexOptions ] , $ operationOptions );
390390
391391 return current ($ names );
392392 }
@@ -400,16 +400,16 @@ public function createSearchIndex($definition, array $options = []): string
400400 * For example:
401401 *
402402 * $indexes = [
403- * // Create a search index with the default name, on
403+ * // Create a search index with the default name on a single field
404404 * ['definition' => ['mappings' => ['dynamic' => false, 'fields' => ['title' => ['type' => 'string']]]]],
405405 * // Create a named search index on all fields
406406 * ['name' => 'search_all', 'definition' => ['mappings' => ['dynamic' => true]]],
407407 * ];
408408 *
409409 * @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/
410410 * @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
413413 * @return string[] The names of the created search indexes
414414 * @throws UnsupportedException if options are not supported by the selected server
415415 * @throws InvalidArgumentException for parameter/option parsing errors
0 commit comments