Skip to content

DOCSP-41987: atlas search idx #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ toc_landing_pages = [
"/reference/class/MongoDBModelIndexInfo",
"/get-started",
"/write",
"/indexes"
]

[substitutions]
Expand Down
57 changes: 57 additions & 0 deletions source/includes/indexes/indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,60 @@
);
echo json_encode($document), PHP_EOL;
// end-index-array-query

// start-create-search-index
$indexName = $collection->createSearchIndex(
['mappings' => ['dynamic' => true]],
['name' => 'mySearchIdx']
);
// end-create-search-index

// start-create-search-indexes
$indexNames = $collection->createSearchIndexes(
[
[
'name' => 'SearchIdx_dynamic',
'definition' => ['mappings' => ['dynamic' => true]],
],
[
'name' => 'SearchIdx_simple',
'definition' => [
'mappings' => [
'dynamic' => false,
'fields' => [
'title' => [
'type' => 'string',
'analyzer' => 'lucene.simple'
]
]
]
],
],
]
);
// end-create-search-indexes

// start-list-search-indexes
foreach ($collection->listSearchIndexes() as $indexInfo) {
echo json_encode($indexInfo), PHP_EOL;
}
// end-list-search-indexes

// start-update-search-indexes
$collection->updateSearchIndex(
'mySearchIdx',
['mappings' => [
'dynamic' => false,
'fields' => [
'title' => [
'type' => 'string',
'analyzer' => 'lucene.simple'
]
]
]]
);
// end-update-search-indexes

// start-delete-search-index
$collection->dropSearchIndex('mySearchIdx');
// end-delete-search-index
23 changes: 6 additions & 17 deletions source/indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Optimize Queries by Using Indexes
/indexes/single-field-index
/indexes/compound-index
/indexes/multikey-index
/indexes/atlas-search-index

Overview
--------
Expand Down Expand Up @@ -221,24 +222,24 @@ The following example deletes an index with the specified name:
:copyable:
:dedent:

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

Atlas Search Index Management
-----------------------------

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

.. note:: Search Index Management is Asynchronous
.. note:: Atlas Search Index Management is Asynchronous

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

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

Create Search Index
~~~~~~~~~~~~~~~~~~~
Expand All @@ -252,9 +253,6 @@ The following example creates an Atlas Search index on the specified field:
:copyable:
:dedent:

.. To learn more about creating search indexes, see the
.. :ref:`php-atlas-search-index-create` guide.

List Search Indexes
~~~~~~~~~~~~~~~~~~~

Expand All @@ -268,9 +266,6 @@ specified collection:
:copyable:
:dedent:

.. To learn more about listing search indexes, see the :ref:`php-atlas-search-index-list`
.. guide.

Update Search Indexes
~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -284,9 +279,6 @@ new index definition:
:copyable:
:dedent:

.. To learn more about updating search indexes, see the :ref:`php-atlas-search-index-update`
.. guide.

Delete Search Indexes
~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -298,6 +290,3 @@ The following example deletes an Atlas Search index with the specified name:
:language: php
:copyable:
:dedent:

.. To learn more about deleting search indexes, see the :ref:`php-atlas-search-index-drop`
.. guide.
149 changes: 149 additions & 0 deletions source/indexes/atlas-search-index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
.. _php-atlas-search-index:

====================
Atlas Search Indexes
====================

.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: index, query, text search, efficiency

Overview
--------

The MongoDB Atlas Search feature enables you to perform full-text
searches on collections hosted on Atlas. Before you can perform Atlas
Search queries, you must create indexes that specify which
fields to index and how they are indexed.

To learn more about Atlas Search, see the :atlas:`Atlas Search Overview
</atlas-search/atlas-search-overview/>`.

You can use the following methods on a ``MongoDB\Collection`` instance
to manage your Atlas Search indexes:

- ``MongoDB\Collection::createSearchIndex()``
- ``MongoDB\Collection::createSearchIndexes()``
- ``MongoDB\Collection::listSearchIndexes()``
- ``MongoDB\Collection::updateSearchIndex()``
- ``MongoDB\Collection::dropSearchIndex()``

.. note:: Atlas Search Index Management is Asynchronous

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

The following sections provide code examples that demonstrate how to use
each Atlas Search index management method.

.. _php-atlas-search-index-create:

Create a Search Index
---------------------

You can use the ``createSearchIndex()`` method to create a single Atlas
Search index on a collection, or the ``createSearchIndexes()`` method to
create multiple indexes simultaneously.

The following code example shows how to create a single Atlas Search
index:

.. literalinclude:: /includes/indexes/indexes.php
:language: php
:start-after: start-create-search-index
:end-before: end-create-search-index

The following code example shows how to create multiple Atlas Search
indexes:

.. literalinclude:: /includes/indexes/indexes.php
:language: php
:start-after: start-create-search-indexes
:end-before: end-create-search-indexes

After you create a Search index, you can perform Atlas Search queries on
your collection. To learn more, see :atlas:`Create and Run Atlas Search
Queries </atlas-search/searching/>` in the Atlas documentation.

.. _php-atlas-search-index-list:

List Search Indexes
-------------------

You can use the ``listSearchIndexes()`` method to return an array of the
Atlas Search indexes on a collection:

.. literalinclude:: /includes/indexes/indexes.php
:language: php
:dedent:
:start-after: start-list-search-indexes
:end-before: end-list-search-indexes

.. _php-atlas-search-index-update:

Update a Search Index
---------------------

You can use the ``updateSearchIndex()``
method to update an Atlas Search index. You can use this method to
change the name of a Search index or change the configuration of the
index.

The following code shows how to update a search index to use a simple
analyzer on the ``title`` field:

.. literalinclude:: /includes/indexes/indexes.php
:language: php
:dedent:
:start-after: start-update-search-indexes
:end-before: end-update-search-indexes

.. _php-atlas-search-index-drop:

Delete a Search Index
---------------------

You can use the ``dropSearchIndex()`` method to remove an Atlas Search
index from a collection.

The following code shows how to delete the Atlas Search index named
``mySearchIdx``:

.. literalinclude:: /includes/indexes/indexes.php
:language: php
:dedent:
:start-after: start-delete-search-index
:end-before: end-delete-search-index

Additional Information
----------------------

To view runnable examples that demonstrate how to manage indexes, see
:ref:`php-indexes`.

To view tutorials that explain how to use the Atlas Search feature, see
:atlas:`Get Started with Atlas Search </atlas-search/tutorial/>` in the
Atlas documentation.

API Documentation
~~~~~~~~~~~~~~~~~

To learn more about any of the methods discussed in this guide, see the
following API documentation:

- :phpmethod:`MongoDB\Collection::createSearchIndex()`
- :phpmethod:`MongoDB\Collection::createSearchIndexes()`
- :phpmethod:`MongoDB\Collection::listSearchIndexes()`
- :phpmethod:`MongoDB\Collection::updateSearchIndex()`
- :phpmethod:`MongoDB\Collection::dropSearchIndex()`
5 changes: 3 additions & 2 deletions source/indexes/index-mgmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ code to programmatically create each type of index.
- :ref:`php-single-field-index`
- :ref:`php-compound-index`
- :ref:`php-multikey-index`

.. - :ref:`php-atlas-search-index`
- :ref:`php-atlas-search-index`

List Indexes
------------
Expand All @@ -84,6 +83,8 @@ You can retrieve a list of indexes on a collection by calling the
:end-before: end-list-indexes
:dedent:

.. _php-remove-idx:

Remove an Index
---------------

Expand Down
4 changes: 2 additions & 2 deletions source/indexes/single-field-index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Indexes </core/index-single>` in the {+mdb-server+} manual.
API Documentation
~~~~~~~~~~~~~~~~~

To learn more about any of the methods discussed in this guide, see the following API
documentation:
To learn more about any of the methods discussed in this guide, see the
following API documentation:

- :phpmethod:`MongoDB\Collection::createIndex()`
- :phpmethod:`MongoDB\Collection::findOne()`
Loading