Skip to content

Commit dfa34c5

Browse files
DOCSP-17260 Direct Text Search traffic to Atlas Search
1 parent c83a7d2 commit dfa34c5

File tree

6 files changed

+107
-96
lines changed

6 files changed

+107
-96
lines changed

source/core/link-text-indexes.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,29 @@ Text Indexes
66

77
.. include:: /includes/fact-text-index.rst
88

9-
.. include:: /includes/fact-create-text-index.rst
10-
119
See the :doc:`/core/index-text` section for a full reference on text
1210
indexes, including behavior, tokenization, and properties.
11+
12+
.. _text-index-eg:
13+
14+
Example
15+
-------
16+
17+
This example demonstrates how to build a text index and use it to find
18+
coffee shops, given only text fields.
19+
20+
Create a collection ``stores`` with the following documents:
21+
22+
.. code-block:: javascript
23+
24+
db.stores.insert(
25+
[
26+
{ _id: 1, name: "Java Hut", description: "Coffee and cakes" },
27+
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },
28+
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
29+
{ _id: 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },
30+
{ _id: 5, name: "Java Shopping", description: "Indonesian goods" }
31+
]
32+
)
33+
34+
.. include:: /includes/fact-create-text-index.rst

source/core/text-search-operators.txt

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,51 @@ operators, including restrictions and behavior, see:
3939

4040
- :expression:`$meta` projection operator
4141

42+
Exact Phrase
43+
````````````
44+
45+
You can also search for exact phrases by wrapping them in double-quotes.
46+
If the ``$search`` string includes a phrase and individual terms, text
47+
search will only match documents that include the phrase.
48+
49+
For example, the following will find all documents containing
50+
"coffee shop":
51+
52+
.. code-block:: javascript
53+
54+
db.stores.find( { $text: { $search: "\"coffee shop\"" } } )
55+
56+
For more information, see :ref:`text-operator-phrases`.
57+
58+
Term Exclusion
59+
``````````````
60+
61+
To exclude a word, you can prepend a "``-``" character. For example, to
62+
find all stores containing "java" or "shop" but not "coffee", use the
63+
following:
64+
65+
.. code-block:: javascript
66+
67+
db.stores.find( { $text: { $search: "java shop -coffee" } } )
68+
69+
Sorting
70+
```````
71+
72+
MongoDB will return its results in unsorted order by default. However,
73+
text search queries will compute a relevance score for each document
74+
that specifies how well a document matches the query.
75+
76+
To sort the results in order of relevance score, you must explicitly
77+
project the :expression:`$meta` ``textScore`` field and sort on it:
78+
79+
.. code-block:: javascript
80+
81+
db.stores.find(
82+
{ $text: { $search: "java coffee shop" } },
83+
{ score: { $meta: "textScore" } }
84+
).sort( { score: { $meta: "textScore" } } )
85+
86+
Text search is also available in the aggregation pipeline.
4287

4388
Aggregation Framework
4489
---------------------
@@ -58,4 +103,3 @@ For more information and examples of text search in the
58103
.. [#meta-aggregation]
59104

60105
.. include:: /includes/fact-meta-operator-disambiguation.rst
61-

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+
You can run the following in :binary:`~bin.mongosh` to allow text
2+
search over the ``name`` and ``description`` fields:
73

84
.. code-block:: javascript
95

source/includes/fact-text-index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
MongoDB provides :ref:`text indexes <index-feature-text>` to support
22
text search queries on string content. ``text`` indexes can include any
3-
field whose value is a string or an array of string elements.
3+
field whose value is a string or an array of string elements. To
4+
perform text search queries, you must have a ``text`` index on your
5+
collection. A collection can only have **one** text search index, but
6+
that index can cover multiple fields.

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/text-search.txt

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

13-
Overview
14-
--------
13+
MongoDB offers a premium full-text search solution, MongoDB Atlas
14+
Search, for MongoDB Atlas users and a legacy text search capability for
15+
self-managed deployments.
1516

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.
17+
MongoDB Atlas Search
18+
--------------------
1919

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-
````````````
20+
For MongoDB Atlas users, MongoDB's Atlas Search supports fine-grained
21+
text indexing using several kinds of text analyzers and searching using
22+
a rich query language. To learn more about full-text search indexes and
23+
:pipeline:`$search` queries, see:
5824

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.
25+
- :atlas:`Atlas Search Aggregation Pipeline Stages
26+
</reference/atlas-search/query-syntax/>`
27+
- :atlas:`Defining Atlas Search Indexes
28+
</reference/atlas-search/index-definitions/>`
29+
- :atlas:`Running Atlas Search Queries
30+
</reference/atlas-search/searching/>`
6231

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.
32+
.. include:: /includes/fact-atlas-search-languages.rst
8933

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

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

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

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

102-
Language Support
103-
----------------
46+
Users running MongoDB software locally can find information on the
47+
legacy text search here:
48+
49+
- :doc:`Text Indexes </core/link-text-indexes/>`
50+
- :doc:`Text Search Operators </core-text-search-operators/>`
10451

105-
MongoDB supports text search for various languages. See
52+
MongoDB also supports text search for various languages. See
10653
:doc:`/reference/text-search-languages` for a list of supported
10754
languages.
10855

109-
.. include:: /includes/fact-atlas-search-languages.rst
110-
11156
.. toctree::
11257
:titlesonly:
11358
:hidden:

0 commit comments

Comments
 (0)