Skip to content

Commit 4adaec3

Browse files
committed
DOCSP-41987: atlas search idx
1 parent a772b6a commit 4adaec3

File tree

5 files changed

+211
-7
lines changed

5 files changed

+211
-7
lines changed

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ Atlas Search Index Management
230230
The following sections contain code examples that describe how to manage
231231
:atlas:`Atlas Search indexes </atlas-search/manage-indexes/>`.
232232

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

235235
The {+php-library+} manages Atlas Search indexes asynchronously. The
236236
library methods described in the following sections return the server
237237
response immediately, but the changes to your Search indexes take
238238
place in the background and might not complete until some time later.
239239

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

243243
Create Search Index
244244
~~~~~~~~~~~~~~~~~~~

source/indexes/atlas-search-index.txt

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

source/indexes/index-mgmt.txt

Lines changed: 1 addition & 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
------------

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)