|
| 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()` |
0 commit comments