Skip to content

Commit e862575

Browse files
committed
DOCS-929 edits to release notes for text search
1 parent dc699fc commit e862575

File tree

1 file changed

+82
-66
lines changed

1 file changed

+82
-66
lines changed

source/release-notes/2.4.txt

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ are *not for production use* under any circumstances.
1313
document are subject to change before the 2.4.0 release.
1414

1515
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
1818
2.3 releases.
1919

2020
.. contents:: See the :doc:`full index of this page <2.4-changes>` for
@@ -98,6 +98,8 @@ indexes have the following limitations and behaviors:
9898
- MongoDB does not stem phrases or negations in :dbcommand:`text`
9999
queries.
100100

101+
- the index is case insensitive.
102+
101103
- a collection may only have a single ``text`` index at a time.
102104

103105
.. important:: Do not enable or use ``text`` indexes on production
@@ -115,7 +117,7 @@ Test ``text`` Indexes
115117

116118
.. important:: The ``text`` index type is an experimental feature and
117119
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
119121
:program:`mongo` shell:
120122

121123
.. code-block:: javascript
@@ -139,7 +141,7 @@ To create a ``text`` index, use the following invocation of
139141

140142
db.collection.ensureIndex( { content: "text" } )
141143

142-
``text`` indexes ignore all string data in the ``content`` field. Your
144+
``text`` indexes catalog all string data in the ``content`` field. Your
143145
``text`` index can include content from multiple fields, or arrays,
144146
and from fields in sub-documents, as in the following:
145147

@@ -149,6 +151,13 @@ and from fields in sub-documents, as in the following:
149151
"users.comments": "text",
150152
"users.profiles": "text" } )
151153

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+
152161
These indexes may run into the :limit:`Index Name Length` limit. To
153162
avoid creating an index with a too-long name, you can specify a name
154163
in the options parameter, as in the following:
@@ -159,8 +168,11 @@ in the options parameter, as in the following:
159168
"users.profiles": "text" },
160169
{ name: "TextIndex" } )
161170

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:
164176

165177
.. code-block:: javascript
166178

@@ -172,18 +184,14 @@ specific, which help shape the result set. Consider the following:
172184

173185
This example creates a ``text`` index on the top-level field named
174186
``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
176188
the ``users.profiles`` field has a weight of 2.
177189

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.
187195

188196
If you create an ascending or descending index as a prefix of a
189197
``text`` index:
@@ -194,34 +202,38 @@ If you create an ascending or descending index as a prefix of a
194202
- All :dbcommand:`text` queries using this index must specify the
195203
prefix field in the ``filter`` query.
196204

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:
201218

202219
.. code-block:: javascript
203220

204221
db.collection.ensureIndex( { "users.profiles": "text",
205222
username: 1 } )
206223

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``:
210228

211229
.. code-block:: javascript
212230

213231
db.collection.ensureIndex( { "$**": "text",
214232
username: 1 },
215233
{ name: "TextIndex" } )
216234

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:
225237

226238
.. code-block:: javascript
227239

@@ -237,7 +249,6 @@ in the following:
237249
keywords: 5,
238250
about: 5 } } )
239251

240-
241252
This index, named ``TextIndex``, includes a number of fields, with the
242253
following weights:
243254

@@ -268,25 +279,31 @@ cursor.
268279

269280
.. code-block:: javascript
270281

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> } )
275287

276288
The :dbcommand:`text` command has the following parameters:
277289

278-
:param string query:
290+
:param string search:
279291

280292
A text string that MongoDB stems and uses to query the ``text``
281293
index. When specifying phrase matches, you must escape quote
282-
characters (i.e. ``"``) with backslashes (i.e. ``\``).
294+
characters as ``\"``.
283295

284296
:param document filter:
285297

286298
Optional. A :ref:`query document <mongodb-query-document>` to
287299
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.
290307

291308
:param document projection:
292309

@@ -298,22 +315,31 @@ cursor.
298315
Optional. Specify the maximum number of documents to include in
299316
the response.
300317

318+
:param string language:
319+
320+
Optional. Specify the language that determines the tokenization,
321+
stemming, and the stop words for the search.
322+
301323
:return:
302324

303325
:dbcommand:`text` returns results in the form of a
304326
document. Results must fit within the :limit:`BSON Document
305327
Size`. Use a projection setting to limit the size of the result
306328
set.
307329

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+
317343
- :dbcommand:`text` adds all negations to the query with the
318344
logical ``AND`` operator.
319345

@@ -345,27 +371,17 @@ cursor.
345371

346372
db.collection.runCommand( "text", { search: "create search fields" } )
347373

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.
352376

353377
#. Search for the exact phrase ``create search fields``:
354378

355379
.. code-block:: javascript
356380

357-
db.collection.runCommand( "text", { search: "\"create search fields\""" } )
381+
db.collection.runCommand( "text", { search: "\"create search fields\"" } )
358382

359383
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``.
369385

370386
#. Search for documents that contain the words ``create`` or ``search``,
371387
but **not** ``fields``:
@@ -385,9 +401,9 @@ cursor.
385401

386402
- A ``<search string>`` that only contains negative words returns no match.
387403

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.
391407

392408
#. Search for a single word ``search`` with an additional ``filter`` on
393409
the ``about`` field, but **limit** the results to 2 documents with the

0 commit comments

Comments
 (0)