Skip to content

fix "and and" in getting started #480

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion source/tutorial/getting-started.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Getting Started with the MongoDB JavaScript Shell

This tutorial provides an introduction to basic database operations
using the :program:`mongo` shell. :program:`mongo` is a part of the
standard MongoDB distribution and and provides a full JavaScript
standard MongoDB distribution and provides a full JavaScript
environment that provides complete access to the JavaScript language
and all standard functions as well as a full database interface for
MongoDB. See the :api:`mongo JavaScript API <js>` documentation and
Expand Down
95 changes: 95 additions & 0 deletions source/tutorial/perform-full-text-search.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
========================
Perform Full-Text Search
========================

.. default-domain:: mongodb

Mongo uses :ref:`multi-key indexes <index-type-multi-key>` to provide
for searches on text and tags. A multi-key index can index an array of
values.

Text Search
-----------

To implement a text search:

1. Create an array of search words.

2. Create a :ref:`multi-key index <index-type-multi-key>` on the array.

.. example::

Create an array with all the keywords to search on. Here is a simple example:

.. code-block:: javascript

{ title : "breakfast drinks" ,
keywords : [ "tea" , "coffee" , "juice", "Tang" ]
}

Create a multi-key index on the ``keywords`` array:

.. code-block:: javascript

db.menu.ensureIndex( { keywords: 1 } )

Tagging
-------

To implement a tag search:

1. Create an array of tags.

2. Create a :ref:`multi-key index <index-type-multi-key>` on the array.

.. example::

Suppose you have documents in the ``articles`` database and the
documents are tagged with category names, such as the following
document:

.. code-block:: javascript

{
name: "Apollo" ,
text: "The Apollo program was the first to land
people on the Moon." ,
tags: [ "moon", "apollo", "spaceflight" ]
}

Create a multi-key index on the ``tags`` array:

.. code-block:: javascript

db.articles.ensureIndex( { tags: 1 } )

The above command indexes all the strings in the ``tags`` array. For
the document shown in this example, the command creates index entries
for the tags ``moon``, ``apollo`` and ``spaceflight``. Users can query
on those tags. For example:

.. code-block:: javascript

print(db.articles.findOne( { tags : "apollo" } ).name)

The database creates an index entry for each item in the array. An
array with many elements (hundreds or thousands) might make inserts very
expensive. Although, for the example above, alternate implementations
are equally expensive.

Comparison to Full-Text Search Engines
--------------------------------------

MongoDB makes certain search full-text searches easy, though differs from
dedicated full-text search engines:

Dedicated full-text engines provide the following:

- Built-in text stemming

- Ranking of queries matching various numbers of terms. This can be done with
MongoDB but requires user supplied code to do so.

- Bulk index building. Bulk index building makes building indexes fast
but has the downside of not being in real time. MongoDB is particularly
well suited for problems where the search should be done in real time.