Skip to content

Commit 883547c

Browse files
committed
DOCSP-41987: atlas search idx
1 parent a040fa8 commit 883547c

File tree

5 files changed

+211
-6
lines changed

5 files changed

+211
-6
lines changed

source/includes/indexes/indexes.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,60 @@
4141
);
4242
echo json_encode($document), PHP_EOL;
4343
// end-index-array-query
44+
45+
// start-create-search-index
46+
$indexName = $collection->createSearchIndex(
47+
['mappings' => ['dynamic' => true]],
48+
['name' => 'mySearchIdx']
49+
);
50+
// end-create-search-index
51+
52+
// start-create-search-indexes
53+
$indexNames = $collection->createSearchIndexes(
54+
[
55+
[
56+
'name' => 'SearchIdx_dynamic',
57+
'definition' => ['mappings' => ['dynamic' => true]],
58+
],
59+
[
60+
'name' => 'SearchIdx_simple',
61+
'definition' => [
62+
'mappings' => [
63+
'dynamic' => false,
64+
'fields' => [
65+
'title' => [
66+
'type' => 'string',
67+
'analyzer' => 'lucene.simple'
68+
]
69+
]
70+
]
71+
],
72+
],
73+
]
74+
);
75+
// end-create-search-indexes
76+
77+
// start-list-search-indexes
78+
foreach ($collection->listSearchIndexes() as $indexInfo) {
79+
echo json_encode($indexInfo), PHP_EOL;
80+
}
81+
// end-list-search-indexes
82+
83+
// start-update-search-indexes
84+
$collection->updateSearchIndex(
85+
'mySearchIdx',
86+
['mappings' => [
87+
'dynamic' => false,
88+
'fields' => [
89+
'title' => [
90+
'type' => 'string',
91+
'analyzer' => 'lucene.simple'
92+
]
93+
]
94+
]]
95+
);
96+
// end-update-search-indexes
97+
98+
// start-delete-search-index
99+
$collection->dropSearchIndex('mySearchIdx');
100+
// end-delete-search-index

source/indexes.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,15 @@ Atlas Search Index Management
228228
The following sections contain code examples that describe how to manage
229229
:atlas:`Atlas Search indexes </atlas-search/manage-indexes/>`.
230230

231-
.. note:: Search Index Management is Asynchronous
231+
.. note:: Atlas Search Index Management is Asynchronous
232232

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

238-
.. To learn more about Atlas Search indexes, see the :ref:`php-atlas-search-index`
239-
.. guide.
238+
To learn more about Atlas Search indexes, see the :ref:`php-atlas-search-index`
239+
guide.
240240

241241
Create Search Index
242242
~~~~~~~~~~~~~~~~~~~

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ code to programmatically create each type of index.
6868

6969
- :ref:`php-single-field-index`
7070
- :ref:`php-multikey-index`
71+
- :ref:`php-atlas-search-index`
7172

7273
.. - :ref:`php-compound-index`
73-
.. - :ref:`php-atlas-search-index`
7474

7575
List Indexes
7676
------------

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)