@@ -32,36 +32,42 @@ functionality:
32
32
- Provides an abstraction to create :atlas:`Atlas Search indexes
33
33
</atlas-search/manage-indexes/>` from any MongoDB or SQL model.
34
34
35
- .. tip::
35
+ .. important:: Use Schema Builder to Create Search Indexes
36
36
37
- We recommend creating Search indexes by using the ``Schema``
38
- builder methods. To learn more, see the :ref:`TODO DOCSP-46230`
39
- section of the Atlas Search guide.
37
+ If your documents are already in MongoDB, create Search indexes
38
+ by using {+php-library+} or ``Schema`` builder methods to improve
39
+ search query performance. To learn more about creating Search
40
+ indexes, see the :ref:`laravel-as-index` section of the Atlas
41
+ Search guide.
40
42
41
43
- Allows you to automatically replicate data from MongoDB into a
42
44
search engine such as `Meilisearch <https://www.meilisearch.com/>`__
43
45
or `Algolia <https://www.algolia.com/>`__. You can use a MongoDB Eloquent
44
- model as the source to import and index.
46
+ model as the source to import and index. To learn more about indexing
47
+ to a search engine, see the `Indexing
48
+ <https://laravel.com/docs/{+laravel-docs-version+}/scout#indexing>`__
49
+ section of the Laravel Scout documentation.
45
50
46
- .. note :: Deployment Compatibility
51
+ .. important :: Deployment Compatibility
47
52
48
53
You can use Laravel Scout only when you connect to MongoDB Atlas
49
- deployments. This feature is not available for self-managed or
50
- serverless deployments.
54
+ deployments. This feature is not available for self-managed
55
+ deployments.
51
56
52
57
Scout for Atlas Search Tutorial
53
58
-------------------------------
54
59
55
- This section demonstrates how to use the Scout integration in your
56
- application to support Atlas Search queries .
60
+ This tutorial demonstrates how to use Scout to compound and index
61
+ documents for MongoDB Atlas Search from Eloquent models (MongoDB or SQL) .
57
62
58
63
.. procedure::
59
64
:style: connected
60
65
61
66
.. step:: Install the Scout package
62
67
63
68
Before you can use Scout in your application, run the following
64
- command from your application's root directory to install Laravel Scout:
69
+ command from your application's root directory to install the
70
+ ``laravel/scout`` package:
65
71
66
72
.. code-block:: bash
67
73
@@ -91,6 +97,12 @@ application to support Atlas Search queries.
91
97
protected $connection = 'mongodb';
92
98
}
93
99
100
+ The ``Searchable`` trait also allows you to reformat documents,
101
+ embed related documents, or transform document values. To learn
102
+ more, see the `Configuring Searchable Data
103
+ <https://laravel.com/docs/{+laravel-docs-version+}/scout#configuring-searchable-data>`__
104
+ section of the Laravel Scout documentation.
105
+
94
106
.. step:: Configure Scout in your application
95
107
96
108
Ensure that your application is configured to use MongoDB as its
@@ -124,6 +136,11 @@ application to support Atlas Search queries.
124
136
- Specifies ``scout_`` as the prefix for the collection name of the
125
137
searchable collection
126
138
139
+ In the ``config/scout.php`` file, you can also specify a custom
140
+ Atlas Search index definition. To learn more, see the :ref:`custom
141
+ index definition example <laravel-scout-custom-index>` in the
142
+ following step.
143
+
127
144
Set the following environment variable in your application's
128
145
``.env`` file to select ``mongodb`` as the default search driver:
129
146
@@ -154,7 +171,7 @@ application to support Atlas Search queries.
154
171
command creates the search collection with an Atlas Search index in your
155
172
MongoDB database. The collection is named ``scout_movies``, based on the prefix
156
173
set in the preceding step. The Atlas Search index is named ``scout``
157
- and has the following configuration:
174
+ and has the following configuration by default :
158
175
159
176
.. code-block:: json
160
177
@@ -163,7 +180,28 @@ application to support Atlas Search queries.
163
180
"dynamic": true
164
181
}
165
182
}
166
-
183
+
184
+ .. _laravel-scout-custom-index:
185
+
186
+ To customize the index definition, add the ``index-definitions``
187
+ configuration to the ``mongodb`` entry in your
188
+ ``config/scout.php`` file. The following code demonstrates how to
189
+ specify a custom index definition for the ``scout_index`` index:
190
+
191
+ .. code-block:: php
192
+
193
+ 'mongodb' => [
194
+ 'connection' => env('SCOUT_MONGODB_CONNECTION', 'mongodb'),
195
+ 'index-definitions' => [
196
+ 'scout_index' => [
197
+ 'mappings' => [
198
+ 'dynamic' => false,
199
+ 'fields' => ['title' => ['type' => 'string']]
200
+ ]
201
+ ]
202
+ ]
203
+ ], ...
204
+
167
205
.. note::
168
206
169
207
MongoDB can take up to a minute to create and finalize
@@ -172,10 +210,11 @@ application to support Atlas Search queries.
172
210
173
211
.. step:: Import data into the searchable collection
174
212
175
- You can use Scout to replicate data from a source collection into a
176
- searchable collection. The following command replicates and indexes data
177
- from the ``movies`` collection into the ``scout_movies`` collection
178
- created in the preceding step:
213
+ You can use Scout to replicate data from a source collection
214
+ modeled by your Eloquent model into a searchable collection. The
215
+ following command replicates and indexes data from the ``movies``
216
+ collection into the ``scout_movies`` collection indexed in the
217
+ preceding step:
179
218
180
219
.. code-block:: bash
181
220
@@ -186,7 +225,7 @@ application to support Atlas Search queries.
186
225
.. tip:: Select Fields to Import
187
226
188
227
You might not need all the fields from your source documents in your
189
- searchable collection. Limiting the fields you replicate can improve
228
+ searchable collection. Limiting the amount of data you replicate can improve
190
229
your application's speed and performance.
191
230
192
231
You can select specific fields to import by defining the
@@ -209,11 +248,6 @@ application to support Atlas Search queries.
209
248
}
210
249
211
250
After completing these steps, you can perform Atlas Search queries on the
212
- ``scout_movies`` collection in your {+odm-long+} application.
213
-
214
- .. TODO add link to Atlas Search guide
215
-
216
- .. TODO Use an External Search Engine
217
- .. -----------------------------
218
-
219
- .. TODO https://jira.mongodb.org/browse/DOCSP-45125
251
+ ``scout_movies`` collection in your {+odm-long+} application. To learn
252
+ how to perform full-text searches, see the :ref:`laravel-atlas-search`
253
+ guide.
0 commit comments