Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1974aec

Browse files
DOCSP-46230: atlas search index mgmt (#3270)
* DOCSP-46230: atlas search index mgmt * fix * fix * small fix * wip * wip * wip * wip * test php link * test php link * RM PR fixes 1 * JT suggestion - move code to tests
1 parent faacf63 commit 1974aec

File tree

5 files changed

+355
-21
lines changed

5 files changed

+355
-21
lines changed

‎docs/eloquent-models/schema-builder.txt

Lines changed: 190 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,15 @@ drop various types of indexes on a collection.
157157
Create an Index
158158
~~~~~~~~~~~~~~~
159159

160-
To create indexes, call the ``create()`` method on the ``Schema`` facade
161-
in your migration file. Pass it the collection name and a callback
162-
method with a ``MongoDB\Laravel\Schema\Blueprint`` parameter. Specify the
163-
index creation details on the ``Blueprint`` instance.
160+
To create indexes, perform the following actions:
161+
162+
1. Call the ``create()`` method on the ``Schema`` facade
163+
in your migration file.
164+
165+
#. Pass it the collection name and a callback method with a
166+
``MongoDB\Laravel\Schema\Blueprint`` parameter.
167+
168+
#. Specify the index creation details on the ``Blueprint`` instance.
164169

165170
The following example migration creates indexes on the following collection
166171
fields:
@@ -262,11 +267,16 @@ indexes:
262267
- Unique indexes, which prevent inserting documents that contain duplicate
263268
values for the indexed field
264269

265-
To create these index types, call the ``create()`` method on the ``Schema`` facade
266-
in your migration file. Pass ``create()`` the collection name and a callback
267-
method with a ``MongoDB\Laravel\Schema\Blueprint`` parameter. Call the
268-
appropriate helper method on the ``Blueprint`` instance and pass the
269-
index creation details.
270+
To create these index types, perform the following actions:
271+
272+
1. Call the ``create()`` method on the ``Schema`` facade
273+
in your migration file.
274+
275+
#. Pass ``create()`` the collection name and a callback method with a
276+
``MongoDB\Laravel\Schema\Blueprint`` parameter.
277+
278+
#. Call the appropriate helper method for the index type on the
279+
``Blueprint`` instance and pass the index creation details.
270280

271281
The following migration code shows how to create a sparse and a TTL index
272282
by using the index helpers. Click the :guilabel:`{+code-output-label+}` button to see
@@ -339,10 +349,16 @@ Create a Geospatial Index
339349
In MongoDB, geospatial indexes let you query geospatial coordinate data for
340350
inclusion, intersection, and proximity.
341351

342-
To create geospatial indexes, call the ``create()`` method on the ``Schema`` facade
343-
in your migration file. Pass ``create()`` the collection name and a callback
344-
method with a ``MongoDB\Laravel\Schema\Blueprint`` parameter. Specify the
345-
geospatial index creation details on the ``Blueprint`` instance.
352+
To create geospatial indexes, perform the following actions:
353+
354+
1. Call the ``create()`` method on the ``Schema`` facade
355+
in your migration file.
356+
357+
#. Pass ``create()`` the collection name and a callback method with a
358+
``MongoDB\Laravel\Schema\Blueprint`` parameter.
359+
360+
#. Specify the geospatial index creation details on the ``Blueprint``
361+
instance.
346362

347363
The following example migration creates a ``2d`` and ``2dsphere`` geospatial
348364
index on the ``spaceports`` collection. Click the :guilabel:`{+code-output-label+}`
@@ -379,11 +395,16 @@ the {+server-docs-name+}.
379395
Drop an Index
380396
~~~~~~~~~~~~~
381397

382-
To drop indexes from a collection, call the ``table()`` method on the
383-
``Schema`` facade in your migration file. Pass it the table name and a
384-
callback method with a ``MongoDB\Laravel\Schema\Blueprint`` parameter.
385-
Call the ``dropIndex()`` method with the index name on the ``Blueprint``
386-
instance.
398+
To drop indexes from a collection, perform the following actions:
399+
400+
1. Call the ``table()`` method on the ``Schema`` facade in your
401+
migration file.
402+
403+
#. Pass it the table name and a callback method with a
404+
``MongoDB\Laravel\Schema\Blueprint`` parameter.
405+
406+
#. Call the ``dropIndex()`` method with the index name on the
407+
``Blueprint`` instance.
387408

388409
.. note::
389410

@@ -399,4 +420,155 @@ from the ``flights`` collection:
399420
:start-after: begin drop index
400421
:end-before: end drop index
401422

423+
.. _laravel-schema-builder-atlas-idx:
424+
425+
Manage Atlas Search and Vector Search Indexes
426+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
427+
428+
In MongoDB, :atlas:`Atlas Search indexes
429+
</atlas-search/manage-indexes/>` support your full-text queries.
430+
:atlas:`Atlas Vector Search indexes
431+
</atlas-vector-search/vector-search-type/>` support similarity
432+
searches that compare query vectors to vector embeddings in your
433+
documents.
434+
435+
View the following guides to learn more about the Atlas Search and
436+
Vector Search features:
437+
438+
- :ref:`laravel-atlas-search` guide
439+
- :ref:`laravel-vector-search` guide
440+
441+
Atlas Search
442+
````````````
443+
444+
To create Atlas Search indexes, perform the following actions:
445+
446+
1. Call the ``create()`` method on the ``Schema`` facade in your
447+
migration file.
448+
449+
#. Pass ``create()`` the collection name and a callback method with a
450+
``MongoDB\Laravel\Schema\Blueprint`` parameter.
451+
452+
#. Pass the Atlas index creation details to the ``searchIndex()`` method
453+
on the ``Blueprint`` instance.
454+
455+
This example migration creates the following Atlas Search indexes on the
456+
``galaxies`` collection:
457+
458+
- ``dynamic_index``: Creates dynamic mappings
459+
- ``auto_index``: Supports autocomplete queries on the ``name`` field
460+
461+
Click the :guilabel:`{+code-output-label+}` button to see the Search
462+
indexes created by running the migration:
463+
464+
.. io-code-block::
465+
466+
.. input:: /includes/schema-builder/galaxies_migration.php
467+
:language: php
468+
:dedent:
469+
:start-after: begin-create-search-indexes
470+
:end-before: end-create-search-indexes
471+
472+
.. output::
473+
:language: json
474+
:visible: false
475+
476+
{
477+
"id": "...",
478+
"name": "dynamic_index",
479+
"type": "search",
480+
"status": "READY",
481+
"queryable": true,
482+
"latestDefinition": {
483+
"mappings": { "dynamic": true }
484+
},
485+
...
486+
}
487+
{
488+
"id": "...",
489+
"name": "auto_index",
490+
"type": "search",
491+
"status": "READY",
492+
"queryable": true,
493+
"latestDefinition": {
494+
"mappings": {
495+
"fields": { "name": [
496+
{ "type": "string", "analyzer": "lucene.english" },
497+
{ "type": "autocomplete", "analyzer": "lucene.english" },
498+
{ "type": "token" }
499+
] }
500+
}
501+
},
502+
...
503+
}
504+
505+
Vector Search
506+
`````````````
507+
508+
To create Vector Search indexes, perform the following actions:
509+
510+
1. Call the ``create()`` method on the ``Schema`` facade in your
511+
migration file.
512+
513+
#. Pass ``create()`` the collection name and a callback method with a
514+
``MongoDB\Laravel\Schema\Blueprint`` parameter.
515+
516+
#. Pass the vector index creation details to the ``vectorSearchIndex()``
517+
method on the ``Blueprint`` instance.
518+
519+
The following example migration creates a Vector Search index called
520+
``vs_index`` on the ``galaxies`` collection.
521+
522+
Click the :guilabel:`{+code-output-label+}` button to see the Search
523+
indexes created by running the migration:
524+
525+
.. io-code-block::
526+
.. input:: /includes/schema-builder/galaxies_migration.php
527+
:language: php
528+
:dedent:
529+
:start-after: begin-create-vs-index
530+
:end-before: end-create-vs-index
402531

532+
.. output::
533+
:language: json
534+
:visible: false
535+
536+
{
537+
"id": "...",
538+
"name": "vs_index",
539+
"type": "vectorSearch",
540+
"status": "READY",
541+
"queryable": true,
542+
"latestDefinition": {
543+
"fields": [ {
544+
"type": "vector",
545+
"numDimensions": 4,
546+
"path": "embeddings",
547+
"similarity": "cosine"
548+
} ]
549+
},
550+
...
551+
}
552+
553+
Drop a Search Index
554+
```````````````````
555+
556+
To drop an Atlas Search or Vector Search index from a collection,
557+
perform the following actions:
558+
559+
1. Call the ``table()`` method on the ``Schema`` facade in your migration file.
560+
561+
#. Pass it the collection name and a callback method with a
562+
``MongoDB\Laravel\Schema\Blueprint`` parameter.
563+
564+
#. Call the ``dropSearchIndex()`` method with the Search index name on
565+
the ``Blueprint`` instance.
566+
567+
The following example migration drops an index called ``auto_index``
568+
from the ``galaxies`` collection:
569+
570+
.. literalinclude:: /includes/schema-builder/galaxies_migration.php
571+
:language: php
572+
:dedent:
573+
:start-after: begin-drop-search-index
574+
:end-before: end-drop-search-index

‎docs/fundamentals/atlas-search.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,25 @@ documentation.
5656
Create an Atlas Search Index
5757
----------------------------
5858

59-
.. TODO in DOCSP-46230
59+
You can create an Atlas Search index in either of the following ways:
60+
61+
- Call the ``create()`` method on the ``Schema`` facade and pass the
62+
``searchIndex()`` helper method with index creation details. To learn
63+
more about this strategy, see the
64+
:ref:`laravel-schema-builder-atlas-idx` section of the Schema Builder guide.
65+
66+
- Access a collection, then call the
67+
:phpmethod:`createSearchIndex() <phpmethod.MongoDB\\Collection::createSearchIndex()>`
68+
method from the {+php-library+}, as shown in the following code:
69+
70+
.. code-block:: php
71+
72+
$collection = DB::connection('mongodb')->getCollection('movies');
73+
74+
$collection->createSearchIndex(
75+
['mappings' => ['dynamic' => true]],
76+
['name' => 'search_index']
77+
);
6078

6179
Perform Queries
6280
---------------

‎docs/fundamentals/vector-search.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,32 @@ documentation.
5656
Create an Atlas Vector Search Index
5757
-----------------------------------
5858

59-
.. TODO in DOCSP-46230
59+
You can create an Atlas Search index in either of the following ways:
60+
61+
- Call the ``create()`` method on the ``Schema`` facade and pass the
62+
``vectorSearchIndex()`` helper method with index creation details. To learn
63+
more about this strategy, see the
64+
:ref:`laravel-schema-builder-atlas-idx` section of the Schema Builder guide.
65+
66+
- Access a collection, then call the
67+
:phpmethod:`createSearchIndex() <phpmethod.MongoDB\\Collection::createSearchIndex()>`
68+
method from the {+php-library+}. You must specify the ``type`` option as
69+
``'vectorSearch'``, as shown in the following code:
70+
71+
.. code-block:: php
72+
73+
$collection = DB::connection('mongodb')->getCollection('movies');
74+
75+
$collection->createSearchIndex([
76+
'fields' => [
77+
[
78+
'type' => 'vector',
79+
'numDimensions' => 4,
80+
'path' => 'embeddings',
81+
'similarity' => 'cosine'
82+
],
83+
],
84+
], ['name' => 'vector_index', 'type' => 'vectorSearch']);
6085

6186
Perform Queries
6287
---------------

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /