Skip to content

DOCSP-17260 Direct Text Search traffic to Atlas Search #5946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions source/core/link-text-indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@ Text Indexes

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

.. include:: /includes/fact-create-text-index.rst

See the :doc:`/core/index-text` section for a full reference on text
indexes, including behavior, tokenization, and properties.

.. _text-index-eg:

Example
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this "Examples" since there are several examples in this section.

-------

This example demonstrates how to build a text index and use it to find
coffee shops, given only text fields.

Create a collection ``stores`` with the following documents:

.. code-block:: javascript

db.stores.insert(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "insert" method is deprecated. Please make this "insertMany".

[
{ _id: 1, name: "Java Hut", description: "Coffee and cakes" },
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
{ _id: 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },
{ _id: 5, name: "Java Shopping", description: "Indonesian goods" }
]
)

.. include:: /includes/fact-create-text-index.rst
46 changes: 45 additions & 1 deletion source/core/text-search-operators.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@ operators, including restrictions and behavior, see:

- :expression:`$meta` projection operator

Exact Phrase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned about the discoverability of these examples. It seems slightly out of place to have them tucked under the "Query Framework" section. These seem like critical use cases we should be highlighting to users.

What if we:

  • Moved these examples to the Text Indexes page
  • Renamed the Text Indexes page to something like "[Perform|Configure] Text Search", to help avoid confusion with the other Text Indexes page.
  • Phrase these section titles more like tasks, so it's clearer what users can do. For example, make this first section "Search for an Exact Phrase"

````````````

You can also search for exact phrases by wrapping them in double-quotes.
If the ``$search`` string includes a phrase and individual terms, text
search will only match documents that include the phrase.

For example, the following will find all documents containing
"coffee shop":

.. code-block:: javascript

db.stores.find( { $text: { $search: "\"coffee shop\"" } } )

For more information, see :ref:`text-operator-phrases`.

Term Exclusion
``````````````

To exclude a word, you can prepend a "``-``" character. For example, to
find all stores containing "java" or "shop" but not "coffee", use the
following:

.. code-block:: javascript

db.stores.find( { $text: { $search: "java shop -coffee" } } )

Sorting
```````

MongoDB will return its results in unsorted order by default. However,
text search queries will compute a relevance score for each document
that specifies how well a document matches the query.

To sort the results in order of relevance score, you must explicitly
project the :expression:`$meta` ``textScore`` field and sort on it:

.. code-block:: javascript

db.stores.find(
{ $text: { $search: "java coffee shop" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )

Text search is also available in the aggregation pipeline.

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

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

8 changes: 2 additions & 6 deletions source/includes/fact-create-text-index.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
To perform text search queries, you must have a
``text`` index on your collection. A collection can only have **one**
text search index, but that index can cover multiple fields.

For example you can run the following in :binary:`~bin.mongosh` to
allow text search over the ``name`` and ``description`` fields:
You can run the following in :binary:`~bin.mongosh` to allow text
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest removing "You can" and being more direct. "Run the following command in...

search over the ``name`` and ``description`` fields:

.. code-block:: javascript

Expand Down
5 changes: 4 additions & 1 deletion source/includes/fact-text-index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
MongoDB provides :ref:`text indexes <index-feature-text>` to support
text search queries on string content. ``text`` indexes can include any
field whose value is a string or an array of string elements.
field whose value is a string or an array of string elements. To
perform text search queries, you must have a ``text`` index on your
collection. A collection can only have **one** text search index, but
that index can cover multiple fields.
3 changes: 2 additions & 1 deletion source/includes/fact-use-text-operator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ punctuation as delimiters, and perform a logical ``OR`` of all such
tokens in the search string.

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

.. code-block:: javascript

Expand Down
115 changes: 30 additions & 85 deletions source/text-search.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,104 +10,49 @@ Text Search
:depth: 1
:class: singlecol

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

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

.. note::

.. include:: /includes/extracts/views-unsupported-text-search.rst

Example
-------

This example demonstrates how to build a text index and use it to find
coffee shops, given only text fields.

Create a collection ``stores`` with the following documents:

.. code-block:: javascript

db.stores.insert(
[
{ _id: 1, name: "Java Hut", description: "Coffee and cakes" },
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
{ _id: 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },
{ _id: 5, name: "Java Shopping", description: "Indonesian goods" }
]
)

Text Index
~~~~~~~~~~

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

.. include:: /includes/fact-create-text-index.rst

``$text`` Operator
~~~~~~~~~~~~~~~~~~

.. include:: /includes/fact-use-text-operator.rst

Exact Phrase
````````````
For MongoDB Atlas users, MongoDB's Atlas Search supports fine-grained
text indexing using several kinds of text analyzers and searching using
a rich query language. To learn more about full-text search indexes and
:pipeline:`$search` queries, see:

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

For example, the following will find all documents containing
"coffee shop":

.. code-block:: javascript

db.stores.find( { $text: { $search: "\"coffee shop\"" } } )

For more information, see :ref:`text-operator-phrases`.

Term Exclusion
``````````````

To exclude a word, you can prepend a "``-``" character. For example, to
find all stores containing "java" or "shop" but not "coffee", use the
following:

.. code-block:: javascript

db.stores.find( { $text: { $search: "java shop -coffee" } } )

Sorting
```````

MongoDB will return its results in unsorted order by default. However,
text search queries will compute a relevance score for each document
that specifies how well a document matches the query.
.. include:: /includes/fact-atlas-search-languages.rst

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

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

db.stores.find(
{ $text: { $search: "java coffee shop" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )
.. note::

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

Language Support
----------------
Users running MongoDB software locally can find information on the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Suggest removing "software".

legacy text search here:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion]

Can we reword this to be a bit more active, as in:

"To learn more about legacy text search for self-managed deployments, see: "


- :doc:`Text Indexes </core/link-text-indexes/>`
- :doc:`Text Search Operators </core-text-search-operators/>`

MongoDB supports text search for various languages. See
MongoDB also supports text search for various languages. See
:doc:`/reference/text-search-languages` for a list of supported
languages.

.. include:: /includes/fact-atlas-search-languages.rst

.. toctree::
:titlesonly:
:hidden:
Expand Down