@@ -53,7 +53,7 @@ Text Indexes
53
53
The ``text`` index type is currently an experimental feature.
54
54
To use a ``text`` index, you need to enable it at run time or
55
55
startup.
56
-
56
+
57
57
Background
58
58
``````````
59
59
@@ -66,7 +66,7 @@ support boolean text search queries:
66
66
67
67
- ``text`` indexes are fully consistent and updated in real-time as
68
68
applications insert, update, or delete documents from the database.
69
-
69
+
70
70
- The ``text`` index and query system supports language specific
71
71
stemming and stop words. Additionally:
72
72
@@ -113,11 +113,11 @@ indexes have the following limitations and behaviors:
113
113
114
114
- A collection may only have a single ``text`` index at a time.
115
115
116
- .. warning::
116
+ .. warning::
117
117
118
118
Do **not** enable or use ``text`` indexes on production systems.
119
119
120
- .. May be worth including this:
120
+ .. May be worth including this:
121
121
122
122
For production-grade search requirements consider using a
123
123
third-party search tool, and the `mongo-connector
@@ -133,9 +133,9 @@ enable the feature before creating or accessing a text index.
133
133
To enable text indexes, issue the following command in the
134
134
:program:`mongo` shell:
135
135
136
- .. warning::
136
+ .. warning::
137
137
138
- Do **not** enable or use ``text`` indexes on production systems.
138
+ Do **not** enable or use ``text`` indexes on production systems.
139
139
140
140
.. code-block:: javascript
141
141
@@ -219,14 +219,14 @@ prefix or suffix of the index. You cannot include :ref:`multi-key
219
219
<index-feature-geospatial>` index field.
220
220
221
221
If you create an ascending or descending index as a prefix of a
222
- ``text`` index:
222
+ ``text`` index:
223
223
224
224
- MongoDB will only index documents that have the prefix field
225
225
(i.e. ``username``) and
226
226
227
227
- The :dbcommand:`text` query can limit the number of index entries to
228
228
review in order to perform the query.
229
-
229
+
230
230
- All :dbcommand:`text` queries using this index must include the
231
231
``filter`` option that specifies an equality condition for the prefix
232
232
field or fields.
@@ -279,7 +279,7 @@ weights for a ``text`` index with compound fields, as in the following:
279
279
about: 5 } } )
280
280
281
281
This index, named ``TextIndex``, includes a number of fields, with the
282
- following weights:
282
+ following weights:
283
283
284
284
- ``content`` field that has a weight of 10,
285
285
- ``users.profiles`` that has a weight of 2,
@@ -292,13 +292,20 @@ will appear in the result set more than all other fields in the index,
292
292
and that the ``user.profiles`` and ``comments`` fields will be less
293
293
likely to appear in responses than words from other fields.
294
294
295
+ .. note::
296
+
297
+ You must drop a ``text`` index using the name specified when you
298
+ created the index. Alternatively, if you did not specify a name
299
+ when creating the index, you can find the name using
300
+ :method:`db.collection.getIndexes()`
301
+
295
302
Text Queries
296
303
^^^^^^^^^^^^
297
304
298
305
MongoDB 2.3.2 introduces the :dbcommand:`text` command to provide
299
306
query support for ``text`` indexes. Unlike normal MongoDB queries,
300
307
:dbcommand:`text` returns a document rather than a
301
- cursor.
308
+ cursor.
302
309
303
310
.. dbcommand:: text
304
311
@@ -321,7 +328,7 @@ cursor.
321
328
A text string that MongoDB stems and uses to query the ``text``
322
329
index. In the :program:`mongo` shell, to specify a phrase to
323
330
match, you can either:
324
-
331
+
325
332
- enclose the phrase in *escaped* double quotes and use double
326
333
quotes to specify the ``search`` string, as in ``"\"coffee
327
334
table\""``, or
@@ -336,8 +343,8 @@ cursor.
336
343
field. You can use any valid MongoDB query in the filter
337
344
document, except if the index includes an ascending or descending
338
345
index field as a prefix.
339
-
340
- If the index includes an ascending or descending index field as a
346
+
347
+ If the index includes an ascending or descending index field as a
341
348
prefix, the ``filter`` is required and the ``filter`` query must be
342
349
an equality match.
343
350
@@ -351,22 +358,22 @@ cursor.
351
358
Optional. Specify the maximum number of documents to include in
352
359
the response. The :dbcommand:`text` sorts the results before
353
360
applying the ``limit``.
354
-
361
+
355
362
The default limit is 100.
356
363
357
364
:param string language:
358
-
365
+
359
366
Optional. Specify the language that determines the tokenization,
360
367
stemming, and the stop words for the search. The default language
361
368
is ``english``.
362
-
369
+
363
370
:return:
364
371
365
372
:dbcommand:`text` returns results, in descending order by score,
366
373
in the form of a document. Results must fit within the
367
374
:limit:`BSON Document Size`. Use the ``limit`` and the
368
375
``projection`` parameters to limit the size of the result set.
369
-
376
+
370
377
371
378
The implicit connector between the terms of a multi-term search is a
372
379
disjunction (``OR``). Search for ``"first second"`` searches
@@ -392,17 +399,17 @@ cursor.
392
399
393
400
#. Create a ``text`` index on the ``content`` field to enable text
394
401
search on the field:
395
-
402
+
396
403
.. code-block:: javascript
397
-
404
+
398
405
db.collection.ensureIndex( { content: "text" } )
399
-
406
+
400
407
#. Search for a single word ``coffee``:
401
-
408
+
402
409
.. code-block:: javascript
403
-
410
+
404
411
db.collection.runCommand( "text", { search: "coffee" } )
405
-
412
+
406
413
This query returns documents that contain the word ``coffee``,
407
414
case-insensitive, in the ``content`` field.
408
415
@@ -418,9 +425,9 @@ cursor.
418
425
#. Search for the exact phrase ``bake coffee cake``:
419
426
420
427
.. code-block:: javascript
421
-
428
+
422
429
db.collection.runCommand( "text", { search: "\"bake coffee cake\"" } )
423
-
430
+
424
431
This query returns documents that contain the exact phrase
425
432
``bake coffee cake``.
426
433
@@ -436,12 +443,12 @@ cursor.
436
443
either ``bake`` **or** ``coffee``, but **not** ``cake``, all
437
444
case-insensitive, in the ``content`` field. Prefixing a word
438
445
with a hyphen (``-``) negates a word:
439
-
446
+
440
447
- The negated word filters out documents from the result set,
441
- after selecting documents.
442
-
448
+ after selecting documents.
449
+
443
450
- A ``<search string>`` that only contains negative words returns no match.
444
-
451
+
445
452
- A hyphenated word, such as ``case-insensitive``, is not a
446
453
negation. The :dbcommand:`text` command treats the hyphen as a
447
454
delimiter.
@@ -450,15 +457,15 @@ cursor.
450
457
the ``about`` field, but **limit** the results to 2 documents with the
451
458
highest score and return only the ``comments`` field in the matching
452
459
documents:
453
-
460
+
454
461
.. code-block:: javascript
455
-
456
- db.collection.runCommand( "text", {
457
- search: "coffee",
458
- filter: { about: /desserts/ },
459
- limit: 2,
460
- projection: { comments: 1, _id: 0 }
461
- }
462
+
463
+ db.collection.runCommand( "text", {
464
+ search: "coffee",
465
+ filter: { about: /desserts/ },
466
+ limit: 2,
467
+ projection: { comments: 1, _id: 0 }
468
+ }
462
469
)
463
470
464
471
- The ``filter`` :ref:`query document <mongodb-query-document>`
@@ -470,7 +477,7 @@ cursor.
470
477
exclude (``0``) the ``_id`` field. Within the ``projection``
471
478
document, you cannot mix inclusions (i.e. ``<fieldA>: 1``) and
472
479
exclusions (i.e. ``<fieldB>: 0``), except for the ``_id`` field.
473
-
480
+
474
481
Additional Authentication Features
475
482
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
476
483
@@ -561,7 +568,7 @@ current connection with the Kerberos session:
561
568
562
569
The value of the ``principal`` field *must* be the same principal that
563
570
you initialized with ``kinit``. This connection will acquire access in
564
- accordance with all privileges granted to this user for all databases.
571
+ accordance with all privileges granted to this user for all databases.
565
572
566
573
.. see:: :doc:`/security`
567
574
0 commit comments