@@ -13,8 +13,8 @@ are *not for production use* under any circumstances.
13
13
document are subject to change before the 2.4.0 release.
14
14
15
15
This document will eventually contain the full release notes for
16
- MongoDB 2.4; during the development cycle this document will containd
17
- ocumentation of new features and functionality only available in the
16
+ MongoDB 2.4; during the development cycle this document will contain
17
+ documentation of new features and functionality only available in the
18
18
2.3 releases.
19
19
20
20
.. contents:: See the :doc:`full index of this page <2.4-changes>` for
@@ -98,6 +98,8 @@ indexes have the following limitations and behaviors:
98
98
- MongoDB does not stem phrases or negations in :dbcommand:`text`
99
99
queries.
100
100
101
+ - the index is case insensitive.
102
+
101
103
- a collection may only have a single ``text`` index at a time.
102
104
103
105
.. important:: Do not enable or use ``text`` indexes on production
@@ -115,7 +117,7 @@ Test ``text`` Indexes
115
117
116
118
.. important:: The ``text`` index type is an experimental feature and
117
119
you must enable the feature before creating or accessing a text
118
- index. To enable text indexes issue the following command at the
120
+ index. To enable text indexes, issue the following command at the
119
121
:program:`mongo` shell:
120
122
121
123
.. code-block:: javascript
@@ -139,7 +141,7 @@ To create a ``text`` index, use the following invocation of
139
141
140
142
db.collection.ensureIndex( { content: "text" } )
141
143
142
- ``text`` indexes ignore all string data in the ``content`` field. Your
144
+ ``text`` indexes catalog all string data in the ``content`` field. Your
143
145
``text`` index can include content from multiple fields, or arrays,
144
146
and from fields in sub-documents, as in the following:
145
147
@@ -149,6 +151,13 @@ and from fields in sub-documents, as in the following:
149
151
"users.comments": "text",
150
152
"users.profiles": "text" } )
151
153
154
+ The default name for the index consists of the ``<field name>``
155
+ concatenated with ``_text``, as in the following:
156
+
157
+ .. code-block:: javascript
158
+
159
+ "content_text_users.comments_text_users.profiles_text"
160
+
152
161
These indexes may run into the :limit:`Index Name Length` limit. To
153
162
avoid creating an index with a too-long name, you can specify a name
154
163
in the options parameter, as in the following:
@@ -159,8 +168,11 @@ in the options parameter, as in the following:
159
168
"users.profiles": "text" },
160
169
{ name: "TextIndex" } )
161
170
162
- When creating a ``text`` indexes you may also specify *weights* for
163
- specific, which help shape the result set. Consider the following:
171
+ When creating ``text`` indexes you may specify *weights* for specific
172
+ fields. *Weights* are factored into the relevant score for each
173
+ document. The score for a given word in a document is the weighted sum
174
+ of the frequency for each of the indexed fields in that document.
175
+ Consider the following:
164
176
165
177
.. code-block:: javascript
166
178
@@ -172,18 +184,14 @@ specific, which help shape the result set. Consider the following:
172
184
173
185
This example creates a ``text`` index on the top-level field named
174
186
``content`` and the ``profiles`` field in the ``users``
175
- sub-documents. Furthermore, ``content`` field has a weight of 1 and
187
+ sub-documents. Furthermore, the ``content`` field has a weight of 1 and
176
188
the ``users.profiles`` field has a weight of 2.
177
189
178
- You can add a conventional ascending or descending index field as a
179
- prefix of the index so that queries can limit the number of index
180
- entries the query must review to perform the query. Create this index
181
- with the following command:
182
-
183
- .. code-block:: javascript
184
-
185
- db.collection.ensureIndex( { username: 1,
186
- "users.profiles": "text" } )
190
+ You can add a conventional ascending or descending index field(s) as a
191
+ prefix or suffix of the index so that queries can limit the number of
192
+ index entries the query must review to perform the query. You cannot
193
+ include :ref:`multi-key <index-type-multi-key>` index field nor
194
+ :ref:`geospatial <index-feature-geospatial>` index field.
187
195
188
196
If you create an ascending or descending index as a prefix of a
189
197
``text`` index:
@@ -194,34 +202,38 @@ If you create an ascending or descending index as a prefix of a
194
202
- All :dbcommand:`text` queries using this index must specify the
195
203
prefix field in the ``filter`` query.
196
204
197
- Alternately you can specify a conventional ascending or descending
198
- field as a suffix to a ``text`` index make it possible to use the
199
- ``text`` index to return covered queries using a projection, as in the
200
- following index:
205
+ Create this index with the following operation:
206
+
207
+ .. code-block:: javascript
208
+
209
+ db.collection.ensureIndex( { username: 1,
210
+ "users.profiles": "text" } )
211
+
212
+ Alternatively you create an ascending or descending index as a suffix
213
+ to a ``text`` index. Then the ``text`` index can support
214
+ :ref:`covered queries <indexes-covered-queries>` if the
215
+ :dbcommand:`text` command specifies a ``projection`` option.
216
+
217
+ Create this index with the following operation:
201
218
202
219
.. code-block:: javascript
203
220
204
221
db.collection.ensureIndex( { "users.profiles": "text",
205
222
username: 1 } )
206
223
207
- Finally, you may use the special wild card field name specifier
208
- (i.e. ``$**``) to specify index weights and fields. Consider the
209
- following:
224
+ Finally, you may use the special wild card field specifier (i.e.
225
+ ``$**``) to specify index weights and fields. Consider the following
226
+ example that indexes any string value in the data of every field of
227
+ every document in a collection and names it ``TextIndex``:
210
228
211
229
.. code-block:: javascript
212
230
213
231
db.collection.ensureIndex( { "$**": "text",
214
232
username: 1 },
215
233
{ name: "TextIndex" } )
216
234
217
- This creates an index named ``TextIndex``, that indexes all string
218
- data in every field of every document in a collection
219
-
220
- .. warning:: Create indexes using the wildcard operator with extreme
221
- caution.
222
-
223
- You may also specify weights for a text index with compound fields, as
224
- in the following:
235
+ By default, an index field has a weight of ``1``. You may specify
236
+ weights for a ``text`` index with compound fields, as in the following:
225
237
226
238
.. code-block:: javascript
227
239
@@ -237,7 +249,6 @@ in the following:
237
249
keywords: 5,
238
250
about: 5 } } )
239
251
240
-
241
252
This index, named ``TextIndex``, includes a number of fields, with the
242
253
following weights:
243
254
@@ -268,25 +279,31 @@ cursor.
268
279
269
280
.. code-block:: javascript
270
281
271
- db.collection.runCommand( "text": { search: <search string>,
272
- filter: <query document>,
273
- projection: <projection document>,
274
- limit: <number> } )
282
+ db.collection.runCommand( "text", { search: <string>,
283
+ filter: <document>,
284
+ projection: <document>,
285
+ limit: <number>,
286
+ language: <string> } )
275
287
276
288
The :dbcommand:`text` command has the following parameters:
277
289
278
- :param string query :
290
+ :param string search :
279
291
280
292
A text string that MongoDB stems and uses to query the ``text``
281
293
index. When specifying phrase matches, you must escape quote
282
- characters (i.e. ``"``) with backslashes (i.e. ``\``) .
294
+ characters as ``\ "``.
283
295
284
296
:param document filter:
285
297
286
298
Optional. A :ref:`query document <mongodb-query-document>` to
287
299
further limit the results of the query using another database
288
- field. If the index is a compound ascending or descending index
289
- field, this query will use that index field.
300
+ field. You can use any valid MongoDB query in the filter
301
+ document, except if the index includes an ascending or descending
302
+ index field as a prefix.
303
+
304
+ If the index includes an ascending or descending index field, the
305
+ ``filter`` is required and the ``filter`` query must be an
306
+ equality match.
290
307
291
308
:param document projection:
292
309
@@ -298,22 +315,31 @@ cursor.
298
315
Optional. Specify the maximum number of documents to include in
299
316
the response.
300
317
318
+ :param string language:
319
+
320
+ Optional. Specify the language that determines the tokenization,
321
+ stemming, and the stop words for the search.
322
+
301
323
:return:
302
324
303
325
:dbcommand:`text` returns results in the form of a
304
326
document. Results must fit within the :limit:`BSON Document
305
327
Size`. Use a projection setting to limit the size of the result
306
328
set.
307
329
308
- Unlike other queries in MongoDB, :dbcommand:`text` takes all the
309
- words in a query an selects matching documents from the index using
310
- a logical ``OR`` operator. However, consider the following
311
- behaviors of :dbcommand:`text` queries:
312
-
313
- - MongoDB adds the words in phrase (i.e. queries enclosed in
314
- quotation marks,) to the search and then adds the praise itself
315
- to the query joined with a logical ``AND``.
316
-
330
+ The implicit connector between the terms of a multi-term search is a
331
+ disjunction (``OR``). Search for ``"first second"`` searches
332
+ for ``"first"`` or ``"second"``. The scoring system will prefer
333
+ documents that contain all terms.
334
+
335
+ However, consider the following behaviors of :dbcommand:`text`
336
+ queries:
337
+
338
+ - With phrases (i.e. terms enclosed in escaped quotes), the search
339
+ performs an ``AND`` with any other terms in the search string;
340
+ e.g. search for ``"\"twinkle twinkle\" little star"`` searches for
341
+ ``"twinkle twinkle"`` and (``"little"`` or ``"star"``).
342
+
317
343
- :dbcommand:`text` adds all negations to the query with the
318
344
logical ``AND`` operator.
319
345
@@ -345,27 +371,17 @@ cursor.
345
371
346
372
db.collection.runCommand( "text", { search: "create search fields" } )
347
373
348
- This query returns documents that contain the either ``creat``
349
- **or** ``search`` **or** ``field`` in the ``content`` field. The
350
- :dbcommand:`text` command has stemmed the word ``create`` to
351
- ``creat`` and the word ``fields`` to ``field`` for the search.
374
+ This query returns documents that contain the either ``create``
375
+ **or** ``search`` **or** ``field`` in the ``content`` field.
352
376
353
377
#. Search for the exact phrase ``create search fields``:
354
378
355
379
.. code-block:: javascript
356
380
357
- db.collection.runCommand( "text", { search: "\"create search fields\""" } )
381
+ db.collection.runCommand( "text", { search: "\"create search fields\"" } )
358
382
359
383
This query returns documents that contain the exact phrase
360
- ``create search fields`` **and** (``creat`` **or** ``search``
361
- **or** ``field``), all case-insensitive, in the ``content``
362
- field.
363
-
364
- .. note::
365
-
366
- Exact phrase matches use the index for the initial selection
367
- phase, but the query must scan the entire result document set
368
- to fulfill the query.
384
+ ``create search fields``.
369
385
370
386
#. Search for documents that contain the words ``create`` or ``search``,
371
387
but **not** ``fields``:
@@ -385,9 +401,9 @@ cursor.
385
401
386
402
- A ``<search string>`` that only contains negative words returns no match.
387
403
388
- - A hyphenated word, such as ``case-insensitive``, is not a negated
389
- word . The :dbcommand:`text` command ignores the hyphen and
390
- searches for either ``case`` or the stem ``insensit`` .
404
+ - A hyphenated word, such as ``case-insensitive``, is not a
405
+ negation . The :dbcommand:`text` command treats the hyphen and
406
+ as a delimiter .
391
407
392
408
#. Search for a single word ``search`` with an additional ``filter`` on
393
409
the ``about`` field, but **limit** the results to 2 documents with the
0 commit comments