Skip to content

Commit dd28d66

Browse files
authored
Merge pull request #143 from rustagir/DOCSP-41987-atlas-search-dx
DOCSP-41987: atlas search idx
2 parents bde5e59 + 61fba29 commit dd28d66

File tree

6 files changed

+218
-21
lines changed

6 files changed

+218
-21
lines changed

snooty.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ toc_landing_pages = [
1919
"/reference/class/MongoDBModelIndexInfo",
2020
"/get-started",
2121
"/write",
22+
"/indexes"
2223
]
2324

2425
[substitutions]

source/includes/indexes/indexes.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,60 @@
5555
);
5656
echo json_encode($document), PHP_EOL;
5757
// end-index-array-query
58+
59+
// start-create-search-index
60+
$indexName = $collection->createSearchIndex(
61+
['mappings' => ['dynamic' => true]],
62+
['name' => 'mySearchIdx']
63+
);
64+
// end-create-search-index
65+
66+
// start-create-search-indexes
67+
$indexNames = $collection->createSearchIndexes(
68+
[
69+
[
70+
'name' => 'SearchIdx_dynamic',
71+
'definition' => ['mappings' => ['dynamic' => true]],
72+
],
73+
[
74+
'name' => 'SearchIdx_simple',
75+
'definition' => [
76+
'mappings' => [
77+
'dynamic' => false,
78+
'fields' => [
79+
'title' => [
80+
'type' => 'string',
81+
'analyzer' => 'lucene.simple'
82+
]
83+
]
84+
]
85+
],
86+
],
87+
]
88+
);
89+
// end-create-search-indexes
90+
91+
// start-list-search-indexes
92+
foreach ($collection->listSearchIndexes() as $indexInfo) {
93+
echo json_encode($indexInfo), PHP_EOL;
94+
}
95+
// end-list-search-indexes
96+
97+
// start-update-search-indexes
98+
$collection->updateSearchIndex(
99+
'mySearchIdx',
100+
['mappings' => [
101+
'dynamic' => false,
102+
'fields' => [
103+
'title' => [
104+
'type' => 'string',
105+
'analyzer' => 'lucene.simple'
106+
]
107+
]
108+
]]
109+
);
110+
// end-update-search-indexes
111+
112+
// start-delete-search-index
113+
$collection->dropSearchIndex('mySearchIdx');
114+
// end-delete-search-index

source/indexes.txt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Optimize Queries by Using Indexes
2626
/indexes/single-field-index
2727
/indexes/compound-index
2828
/indexes/multikey-index
29+
/indexes/atlas-search-index
2930

3031
Overview
3132
--------
@@ -221,24 +222,24 @@ The following example deletes an index with the specified name:
221222
:copyable:
222223
:dedent:
223224

224-
.. TODO: To learn more about removing indexes, see :ref:`php-indexes-remove`
225-
.. in the Work with Indexes guide.
225+
To learn more about deleting indexes, see :ref:`php-remove-idx`
226+
in the Index Considerations and Management guide.
226227

227228
Atlas Search Index Management
228229
-----------------------------
229230

230231
The following sections contain code examples that describe how to manage
231232
:atlas:`Atlas Search indexes </atlas-search/manage-indexes/>`.
232233

233-
.. note:: Search Index Management is Asynchronous
234+
.. note:: Atlas Search Index Management is Asynchronous
234235

235236
The {+php-library+} manages Atlas Search indexes asynchronously. The
236237
library methods described in the following sections return the server
237238
response immediately, but the changes to your Search indexes take
238239
place in the background and might not complete until some time later.
239240

240-
.. To learn more about Atlas Search indexes, see the :ref:`php-atlas-search-index`
241-
.. guide.
241+
To learn more about Atlas Search indexes, see the :ref:`php-atlas-search-index`
242+
guide.
242243

243244
Create Search Index
244245
~~~~~~~~~~~~~~~~~~~
@@ -252,9 +253,6 @@ The following example creates an Atlas Search index on the specified field:
252253
:copyable:
253254
:dedent:
254255

255-
.. To learn more about creating search indexes, see the
256-
.. :ref:`php-atlas-search-index-create` guide.
257-
258256
List Search Indexes
259257
~~~~~~~~~~~~~~~~~~~
260258

@@ -268,9 +266,6 @@ specified collection:
268266
:copyable:
269267
:dedent:
270268

271-
.. To learn more about listing search indexes, see the :ref:`php-atlas-search-index-list`
272-
.. guide.
273-
274269
Update Search Indexes
275270
~~~~~~~~~~~~~~~~~~~~~
276271

@@ -284,9 +279,6 @@ new index definition:
284279
:copyable:
285280
:dedent:
286281

287-
.. To learn more about updating search indexes, see the :ref:`php-atlas-search-index-update`
288-
.. guide.
289-
290282
Delete Search Indexes
291283
~~~~~~~~~~~~~~~~~~~~~
292284

@@ -298,6 +290,3 @@ The following example deletes an Atlas Search index with the specified name:
298290
:language: php
299291
:copyable:
300292
:dedent:
301-
302-
.. To learn more about deleting search indexes, see the :ref:`php-atlas-search-index-drop`
303-
.. guide.

source/indexes/atlas-search-index.txt

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
.. _php-atlas-search-index:
2+
3+
====================
4+
Atlas Search Indexes
5+
====================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: index, query, text search, efficiency
19+
20+
Overview
21+
--------
22+
23+
The MongoDB Atlas Search feature enables you to perform full-text
24+
searches on collections hosted on Atlas. Before you can perform Atlas
25+
Search queries, you must create indexes that specify which
26+
fields to index and how they are indexed.
27+
28+
To learn more about Atlas Search, see the :atlas:`Atlas Search Overview
29+
</atlas-search/atlas-search-overview/>`.
30+
31+
You can use the following methods on a ``MongoDB\Collection`` instance
32+
to manage your Atlas Search indexes:
33+
34+
- ``MongoDB\Collection::createSearchIndex()``
35+
- ``MongoDB\Collection::createSearchIndexes()``
36+
- ``MongoDB\Collection::listSearchIndexes()``
37+
- ``MongoDB\Collection::updateSearchIndex()``
38+
- ``MongoDB\Collection::dropSearchIndex()``
39+
40+
.. note:: Atlas Search Index Management is Asynchronous
41+
42+
The {+php-library+} manages Atlas Search indexes asynchronously. The
43+
library methods described in the following sections return the server
44+
response immediately, but the changes to your Search indexes take
45+
place in the background and might not complete until some time later.
46+
47+
The following sections provide code examples that demonstrate how to use
48+
each Atlas Search index management method.
49+
50+
.. _php-atlas-search-index-create:
51+
52+
Create a Search Index
53+
---------------------
54+
55+
You can use the ``createSearchIndex()`` method to create a single Atlas
56+
Search index on a collection, or the ``createSearchIndexes()`` method to
57+
create multiple indexes simultaneously.
58+
59+
The following code example shows how to create a single Atlas Search
60+
index:
61+
62+
.. literalinclude:: /includes/indexes/indexes.php
63+
:language: php
64+
:start-after: start-create-search-index
65+
:end-before: end-create-search-index
66+
67+
The following code example shows how to create multiple Atlas Search
68+
indexes:
69+
70+
.. literalinclude:: /includes/indexes/indexes.php
71+
:language: php
72+
:start-after: start-create-search-indexes
73+
:end-before: end-create-search-indexes
74+
75+
After you create a Search index, you can perform Atlas Search queries on
76+
your collection. To learn more, see :atlas:`Create and Run Atlas Search
77+
Queries </atlas-search/searching/>` in the Atlas documentation.
78+
79+
.. _php-atlas-search-index-list:
80+
81+
List Search Indexes
82+
-------------------
83+
84+
You can use the ``listSearchIndexes()`` method to return an array of the
85+
Atlas Search indexes on a collection:
86+
87+
.. literalinclude:: /includes/indexes/indexes.php
88+
:language: php
89+
:dedent:
90+
:start-after: start-list-search-indexes
91+
:end-before: end-list-search-indexes
92+
93+
.. _php-atlas-search-index-update:
94+
95+
Update a Search Index
96+
---------------------
97+
98+
You can use the ``updateSearchIndex()``
99+
method to update an Atlas Search index. You can use this method to
100+
change the name of a Search index or change the configuration of the
101+
index.
102+
103+
The following code shows how to update a search index to use a simple
104+
analyzer on the ``title`` field:
105+
106+
.. literalinclude:: /includes/indexes/indexes.php
107+
:language: php
108+
:dedent:
109+
:start-after: start-update-search-indexes
110+
:end-before: end-update-search-indexes
111+
112+
.. _php-atlas-search-index-drop:
113+
114+
Delete a Search Index
115+
---------------------
116+
117+
You can use the ``dropSearchIndex()`` method to remove an Atlas Search
118+
index from a collection.
119+
120+
The following code shows how to delete the Atlas Search index named
121+
``mySearchIdx``:
122+
123+
.. literalinclude:: /includes/indexes/indexes.php
124+
:language: php
125+
:dedent:
126+
:start-after: start-delete-search-index
127+
:end-before: end-delete-search-index
128+
129+
Additional Information
130+
----------------------
131+
132+
To view runnable examples that demonstrate how to manage indexes, see
133+
:ref:`php-indexes`.
134+
135+
To view tutorials that explain how to use the Atlas Search feature, see
136+
:atlas:`Get Started with Atlas Search </atlas-search/tutorial/>` in the
137+
Atlas documentation.
138+
139+
API Documentation
140+
~~~~~~~~~~~~~~~~~
141+
142+
To learn more about any of the methods discussed in this guide, see the
143+
following API documentation:
144+
145+
- :phpmethod:`MongoDB\Collection::createSearchIndex()`
146+
- :phpmethod:`MongoDB\Collection::createSearchIndexes()`
147+
- :phpmethod:`MongoDB\Collection::listSearchIndexes()`
148+
- :phpmethod:`MongoDB\Collection::updateSearchIndex()`
149+
- :phpmethod:`MongoDB\Collection::dropSearchIndex()`

source/indexes/index-mgmt.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ code to programmatically create each type of index.
6969
- :ref:`php-single-field-index`
7070
- :ref:`php-compound-index`
7171
- :ref:`php-multikey-index`
72-
73-
.. - :ref:`php-atlas-search-index`
72+
- :ref:`php-atlas-search-index`
7473

7574
List Indexes
7675
------------
@@ -84,6 +83,8 @@ You can retrieve a list of indexes on a collection by calling the
8483
:end-before: end-list-indexes
8584
:dedent:
8685

86+
.. _php-remove-idx:
87+
8788
Remove an Index
8889
---------------
8990

source/indexes/single-field-index.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ Indexes </core/index-single>` in the {+mdb-server+} manual.
9292
API Documentation
9393
~~~~~~~~~~~~~~~~~
9494

95-
To learn more about any of the methods discussed in this guide, see the following API
96-
documentation:
95+
To learn more about any of the methods discussed in this guide, see the
96+
following API documentation:
9797

9898
- :phpmethod:`MongoDB\Collection::createIndex()`
9999
- :phpmethod:`MongoDB\Collection::findOne()`

0 commit comments

Comments
 (0)