-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from 1 commit
dfa34c5
17ecefa
e83daad
54c5f79
f788d4b
628ad20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
------- | ||
|
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
jason-price-mongodb marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,51 @@ operators, including restrictions and behavior, see: | |
|
||
- :expression:`$meta` projection operator | ||
|
||
Exact Phrase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
```````````` | ||
|
||
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 | ||
--------------------- | ||
|
@@ -58,4 +103,3 @@ For more information and examples of text search in the | |
.. [#meta-aggregation] | ||
|
||
.. include:: /includes/fact-meta-operator-disambiguation.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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Suggest removing "software". |
||
legacy text search here: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
There was a problem hiding this comment.
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.