Skip to content

Commit d9c6a57

Browse files
DOCSP-20469 Backport text search updates to 5.0 (#354)
* DOCSP-17260 Direct Text Search traffic to Atlas Search (#5946) * DOCSP-17260 Direct Text Search traffic to Atlas Search * DOCSP-17260 updates for copy review feedback * DOCSP-17260 2nd round of updates for copy review feedback * DOCSP-17260 updates for review feedback * DOCSP-17260 added link to search and intro to two more pages * DOCSP-17260 addressing Jenny's feedback comments * fix text search url Co-authored-by: kanchana-mongodb <[email protected]>
1 parent d33d4c2 commit d9c6a57

10 files changed

+139
-110
lines changed

source/core/link-text-indexes.txt

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,89 @@
1-
============
2-
Text Indexes
3-
============
1+
==============================
2+
Perform a Text Search (Legacy)
3+
==============================
44

55
.. default-domain:: mongodb
66

7-
.. include:: /includes/fact-text-index.rst
87

9-
.. include:: /includes/fact-create-text-index.rst
8+
.. include:: /includes/fact-text-search-legacy-atlas.rst
9+
10+
.. include:: /includes/fact-text-index.rst
1011

1112
See the :doc:`/core/index-text` section for a full reference on text
1213
indexes, including behavior, tokenization, and properties.
14+
15+
.. _text-index-eg:
16+
17+
Examples
18+
--------
19+
20+
This example demonstrates how to build a text index and use it to find
21+
coffee shops, given only text fields.
22+
23+
Create a Collection
24+
~~~~~~~~~~~~~~~~~~~
25+
26+
Create a collection ``stores`` with the following documents:
27+
28+
.. code-block:: javascript
29+
30+
db.stores.insertMany(
31+
[
32+
{ _id: 1, name: "Java Hut", description: "Coffee and cakes" },
33+
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },
34+
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
35+
{ _id: 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },
36+
{ _id: 5, name: "Java Shopping", description: "Indonesian goods" }
37+
]
38+
)
39+
40+
Create a Text Index
41+
~~~~~~~~~~~~~~~~~~~
42+
43+
.. include:: /includes/fact-create-text-index.rst
44+
45+
Search for an Exact Phrase
46+
~~~~~~~~~~~~~~~~~~~~~~~~~~
47+
48+
You can also search for exact phrases by wrapping them in double-quotes.
49+
If the ``$search`` string includes a phrase and individual terms, text
50+
search will only match documents that include the phrase.
51+
52+
For example, the following will find all documents containing
53+
"coffee shop":
54+
55+
.. code-block:: javascript
56+
57+
db.stores.find( { $text: { $search: "\"coffee shop\"" } } )
58+
59+
For more information, see :ref:`text-operator-phrases`.
60+
61+
Exclude a Term
62+
~~~~~~~~~~~~~~
63+
64+
To exclude a word, you can prepend a "``-``" character. For example, to
65+
find all stores containing "java" or "shop" but not "coffee", use the
66+
following:
67+
68+
.. code-block:: javascript
69+
70+
db.stores.find( { $text: { $search: "java shop -coffee" } } )
71+
72+
Sort the Results
73+
~~~~~~~~~~~~~~~~
74+
75+
MongoDB will return its results in unsorted order by default. However,
76+
text search queries will compute a relevance score for each document
77+
that specifies how well a document matches the query.
78+
79+
To sort the results in order of relevance score, you must explicitly
80+
project the :expression:`$meta` ``textScore`` field and sort on it:
81+
82+
.. code-block:: javascript
83+
84+
db.stores.find(
85+
{ $text: { $search: "java coffee shop" } },
86+
{ score: { $meta: "textScore" } }
87+
).sort( { score: { $meta: "textScore" } } )
88+
89+
Text search is also available in the aggregation pipeline.

source/core/text-search-operators.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=====================
2-
Text Search Operators
3-
=====================
1+
==============================
2+
Text Search Operators (Legacy)
3+
==============================
44

55
.. default-domain:: mongodb
66

@@ -10,6 +10,8 @@ Text Search Operators
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. include:: /includes/fact-text-search-legacy-atlas.rst
14+
1315
.. note::
1416

1517
.. include:: /includes/extracts/views-unsupported-text-search.rst
@@ -39,13 +41,12 @@ operators, including restrictions and behavior, see:
3941

4042
- :expression:`$meta` projection operator
4143

42-
4344
Aggregation Framework
4445
---------------------
4546

4647
When working with the :doc:`/aggregation` framework, use
4748
:pipeline:`$match` with a :query:`$text` expression to execute a text
48-
search query. To sort the results in order of relevance score,use the
49+
search query. To sort the results in order of relevance score, use the
4950
:expression:`$meta` *aggregation operator* in the :pipeline:`$sort`
5051
stage [#meta-aggregation]_.
5152

@@ -58,4 +59,3 @@ For more information and examples of text search in the
5859
.. [#meta-aggregation]
5960

6061
.. include:: /includes/fact-meta-operator-disambiguation.rst
61-
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
For data hosted on MongoDB Atlas, :atlas:`Atlas Search </atlas-search>`
2-
provides support for additional languages. To see the complete list of
3-
languages supported by Atlas Search, see the :atlas:`Atlas Search
4-
Language Analyzers </reference/atlas-search/analyzers/language/>`.
1+
:atlas:`Atlas Search </atlas-search>` also offers common
2+
:atlas:`analyzers for parsing text for full-text search
3+
</reference/atlas-search/analyzers/>`, including support for over
4+
:atlas:`40 language-specific analyzers
5+
</reference/atlas-search/analyzers/language/>`.

source/includes/fact-create-text-index.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
To perform text search queries, you must have a
2-
``text`` index on your collection. A collection can only have **one**
3-
text search index, but that index can cover multiple fields.
4-
5-
For example you can run the following in :binary:`~bin.mongosh` to
6-
allow text search over the ``name`` and ``description`` fields:
1+
Run the following in :binary:`~bin.mongosh` to allow text search over
2+
the ``name`` and ``description`` fields:
73

84
.. code-block:: javascript
95

source/includes/fact-text-index.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
MongoDB provides :ref:`text indexes <index-feature-text>` to support
2-
text search queries on string content. ``text`` indexes can include any
3-
field whose value is a string or an array of string elements.
1+
To run legacy text search queries, you must have a ``text`` index on
2+
your collection. MongoDB provides :ref:`text indexes
3+
<index-feature-text>` to support text search queries on string content.
4+
``text`` indexes can include any field whose value is a string or an
5+
array of string elements. A collection can only have **one** text
6+
search index, but that index can cover multiple fields.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MongoDB offers a :atlas:`premium full-text search solution, MongoDB
2+
Atlas Search </atlas-search/>`, for data hosted on :atlas:`MongoDB
3+
Atlas </>`. A legacy text search capability is available for users
4+
self-managing MongoDB deployments.

source/includes/fact-use-text-operator.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ punctuation as delimiters, and perform a logical ``OR`` of all such
66
tokens in the search string.
77

88
For example, you could use the following query to find all stores
9-
containing any terms from the list "coffee", "shop", and "java":
9+
containing any terms from the list "coffee", "shop", and "java" in
10+
the ``stores`` :ref:`collection <text-index-eg>`:
1011

1112
.. code-block:: javascript
1213

source/reference/text-search-languages.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Text Search Languages
1212
:depth: 1
1313
:class: singlecol
1414

15+
.. include:: /includes/fact-text-search-legacy-atlas.rst
16+
1517
The :ref:`text index <index-feature-text>` and the :query:`$text`
1618
operator may be used with the following languages, and accepts either the
1719
two-letter ISO 639-1 language code or the long form of the

source/text-search.txt

Lines changed: 28 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10,104 +10,47 @@ Text Search
1010
:depth: 1
1111
:class: singlecol
1212

13-
Overview
14-
--------
13+
.. include:: /includes/fact-text-search-legacy-atlas.rst
1514

16-
MongoDB supports query operations that perform a text search of string
17-
content. To perform text search, MongoDB uses a
18-
:ref:`text index <index-feature-text>` and the :query:`$text` operator.
15+
MongoDB Atlas Search
16+
--------------------
1917

20-
.. note::
21-
22-
.. include:: /includes/extracts/views-unsupported-text-search.rst
23-
24-
Example
25-
-------
26-
27-
This example demonstrates how to build a text index and use it to find
28-
coffee shops, given only text fields.
29-
30-
Create a collection ``stores`` with the following documents:
31-
32-
.. code-block:: javascript
33-
34-
db.stores.insert(
35-
[
36-
{ _id: 1, name: "Java Hut", description: "Coffee and cakes" },
37-
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },
38-
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
39-
{ _id: 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },
40-
{ _id: 5, name: "Java Shopping", description: "Indonesian goods" }
41-
]
42-
)
43-
44-
Text Index
45-
~~~~~~~~~~
46-
47-
.. include:: /includes/fact-text-index.rst
48-
49-
.. include:: /includes/fact-create-text-index.rst
50-
51-
``$text`` Operator
52-
~~~~~~~~~~~~~~~~~~
53-
54-
.. include:: /includes/fact-use-text-operator.rst
55-
56-
Exact Phrase
57-
````````````
18+
For MongoDB Atlas users, MongoDB's Atlas Search supports fine-grained
19+
text indexing and a rich query language for fast, relevant search
20+
results. To learn more about full-text search indexes and
21+
:pipeline:`$search` queries, see:
5822

59-
You can also search for exact phrases by wrapping them in double-quotes.
60-
If the ``$search`` string includes a phrase and individual terms, text search
61-
will only match documents that include the phrase.
23+
- :atlas:`Atlas Search Aggregation Pipeline Stages
24+
</reference/atlas-search/query-syntax/>`
25+
- :atlas:`Defining Atlas Search Indexes
26+
</reference/atlas-search/index-definitions/>`
27+
- :atlas:`Running Atlas Search Queries
28+
</reference/atlas-search/searching/>`
6229

63-
For example, the following will find all documents containing
64-
"coffee shop":
65-
66-
.. code-block:: javascript
67-
68-
db.stores.find( { $text: { $search: "\"coffee shop\"" } } )
69-
70-
For more information, see :ref:`text-operator-phrases`.
71-
72-
Term Exclusion
73-
``````````````
74-
75-
To exclude a word, you can prepend a "``-``" character. For example, to
76-
find all stores containing "java" or "shop" but not "coffee", use the
77-
following:
78-
79-
.. code-block:: javascript
80-
81-
db.stores.find( { $text: { $search: "java shop -coffee" } } )
82-
83-
Sorting
84-
```````
85-
86-
MongoDB will return its results in unsorted order by default. However,
87-
text search queries will compute a relevance score for each document
88-
that specifies how well a document matches the query.
30+
.. include:: /includes/fact-atlas-search-languages.rst
8931

90-
To sort the results in order of relevance score, you must explicitly
91-
project the :expression:`$meta` ``textScore`` field and sort on it:
32+
Legacy Text Search
33+
------------------
9234

93-
.. code-block:: javascript
35+
For self-managed deployments, MongoDB's legacy text search capability
36+
supports query operations that perform a text search of string content.
37+
To perform text search, MongoDB uses a :ref:`text index
38+
<index-feature-text>` and the :query:`$text` operator.
9439

95-
db.stores.find(
96-
{ $text: { $search: "java coffee shop" } },
97-
{ score: { $meta: "textScore" } }
98-
).sort( { score: { $meta: "textScore" } } )
40+
.. note::
9941

100-
Text search is also available in the aggregation pipeline.
42+
.. include:: /includes/extracts/views-unsupported-text-search.rst
10143

102-
Language Support
103-
----------------
44+
To learn more about legacy text search for self-managed deployments,
45+
see:
46+
47+
- :doc:`Text Indexes </core/link-text-indexes/>`
48+
- :doc:`Text Search Operators </core/text-search-operators/>`
10449

105-
MongoDB supports text search for various languages. See
50+
MongoDB also supports text search for various languages. See
10651
:doc:`/reference/text-search-languages` for a list of supported
10752
languages.
10853

109-
.. include:: /includes/fact-atlas-search-languages.rst
110-
11154
.. toctree::
11255
:titlesonly:
11356
:hidden:

source/tutorial/text-search-in-aggregation.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Text Search in the Aggregation Pipeline
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. include:: /includes/fact-text-search-legacy-atlas.rst
14+
1315
.. _text-agg-expression-behavior:
1416

1517
In the aggregation pipeline, text search is available via the use of

0 commit comments

Comments
 (0)