Skip to content

Commit 9bea3b1

Browse files
committed
text index - clarify examples by using different values; also add Rassi's comments regarding sort and limits
1 parent 8166735 commit 9bea3b1

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

source/release-notes/2.4.txt

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,15 @@ invocation:
151151
Create Text Indexes
152152
^^^^^^^^^^^^^^^^^^^
153153

154-
To create a ``text`` index, use the following invocation of
154+
To create a ``text`` index, use the following syntax of
155155
:method:`~db.collection.ensureIndex()`:
156156

157+
.. code-block:: javascript
158+
159+
db.collection.ensureIndex( { <field>: "text" } )
160+
161+
Consider the following example:
162+
157163
.. code-block:: javascript
158164

159165
db.collection.ensureIndex( { content: "text" } )
@@ -341,9 +347,12 @@ cursor.
341347
to only those specified.
342348

343349
:param number limit:
344-
350+
345351
Optional. Specify the maximum number of documents to include in
346-
the response. The default limit is 100.
352+
the response. The :dbcommand:`text` sorts the results before
353+
applying the ``limit``.
354+
355+
The default limit is 100.
347356

348357
:param string language:
349358

@@ -353,10 +362,11 @@ cursor.
353362

354363
:return:
355364

356-
:dbcommand:`text` returns results in the form of a document.
357-
Results must fit within the :limit:`BSON Document Size`. Use the
358-
``limit`` and the ``projection`` parameters to limit the size of
359-
the result set.
365+
:dbcommand:`text` returns results, in descending order by score,
366+
in the form of a document. Results must fit within the
367+
:limit:`BSON Document Size`. Use the ``limit`` and the
368+
``projection`` parameters to limit the size of the result set.
369+
360370

361371
The implicit connector between the terms of a multi-term search is a
362372
disjunction (``OR``). Search for ``"first second"`` searches
@@ -387,43 +397,43 @@ cursor.
387397

388398
db.collection.ensureIndex( { content: "text" } )
389399

390-
#. Search for a single word ``search``:
400+
#. Search for a single word ``coffee``:
391401

392402
.. code-block:: javascript
393403

394-
db.collection.runCommand( "text", { search: "search" } )
404+
db.collection.runCommand( "text", { search: "coffee" } )
395405

396-
This query returns documents that contain the word ``search``,
406+
This query returns documents that contain the word ``coffee``,
397407
case-insensitive, in the ``content`` field.
398408

399-
#. Search for multiple words, ``create`` or ``search`` or ``fields``:
409+
#. Search for multiple words, ``bake`` or ``coffee`` or ``cake``:
400410

401411
.. code-block:: javascript
402412

403-
db.collection.runCommand( "text", { search: "create search fields" } )
413+
db.collection.runCommand( "text", { search: "bake coffee cake" } )
404414

405-
This query returns documents that contain the either ``create``
406-
**or** ``search`` **or** ``field`` in the ``content`` field.
415+
This query returns documents that contain the either ``bake``
416+
**or** ``coffee`` **or** ``cake`` in the ``content`` field.
407417

408-
#. Search for the exact phrase ``create search fields``:
418+
#. Search for the exact phrase ``bake coffee cake``:
409419

410420
.. code-block:: javascript
411421

412-
db.collection.runCommand( "text", { search: "\"create search fields\"" } )
422+
db.collection.runCommand( "text", { search: "\"bake coffee cake\"" } )
413423

414424
This query returns documents that contain the exact phrase
415-
``create search fields``.
425+
``bake coffee cake``.
426+
427+
#. Search for documents that contain the words ``bake`` or ``coffee``,
428+
but **not** ``cake``:
416429

417-
#. Search for documents that contain the words ``create`` or ``search``,
418-
but **not** ``fields``:
419-
420430
.. code-block:: javascript
421-
422-
db.collection.runCommand( "text", { search: "create search -fields" } )
423-
431+
432+
db.collection.runCommand( "text", { search: "bake coffee -cake" } )
433+
424434
Use the ``-`` as a prefix to terms to specify negation in the
425435
search string. The query returns documents that contain the
426-
either ``create`` **or** ``search``, but **not** ``field``, all
436+
either ``bake`` **or** ``coffee``, but **not** ``cake``, all
427437
case-insensitive, in the ``content`` field. Prefixing a word
428438
with a hyphen (``-``) negates a word:
429439

@@ -436,25 +446,24 @@ cursor.
436446
negation. The :dbcommand:`text` command treats the hyphen as a
437447
delimiter.
438448

439-
#. Search for a single word ``search`` with an additional ``filter`` on
449+
#. Search for a single word ``coffee`` with an additional ``filter`` on
440450
the ``about`` field, but **limit** the results to 2 documents with the
441451
highest score and return only the ``comments`` field in the matching
442452
documents:
443453

444454
.. code-block:: javascript
445455

446456
db.collection.runCommand( "text", {
447-
search: "insensitive",
448-
filter: { about: /something/ },
457+
search: "coffee",
458+
filter: { about: /desserts/ },
449459
limit: 2,
450460
projection: { comments: 1, _id: 0 }
451461
}
452462
)
453463

454464
- The ``filter`` :ref:`query document <mongodb-query-document>`
455-
uses a :operator:`regular expression <$regex>`. See the
456-
:doc:`query operators </reference/operator>` page for available query
457-
operators.
465+
may use any of the available :doc:`query operators
466+
</reference/operator>`.
458467

459468
- Because the ``_id`` field is implicitly included, in order to
460469
return **only** the ``comments`` field, you must explicitly

0 commit comments

Comments
 (0)