From 261431a8af20c7faf85167f3367c6bb5e0a41d42 Mon Sep 17 00:00:00 2001 From: Bob Grabar Date: Thu, 13 Dec 2012 21:08:04 -0500 Subject: [PATCH 1/2] DOCS-797 full-text search --- source/tutorial/perform-full-text-search.txt | 95 ++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 source/tutorial/perform-full-text-search.txt diff --git a/source/tutorial/perform-full-text-search.txt b/source/tutorial/perform-full-text-search.txt new file mode 100644 index 00000000000..123fb76dd99 --- /dev/null +++ b/source/tutorial/perform-full-text-search.txt @@ -0,0 +1,95 @@ +======================== +Perform Full-Text Search +======================== + +.. default-domain:: mongodb + +Mongo uses :ref:`multi-key indexes ` 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 ` 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 ` 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. From 5e56adcb811b7b06f55faaffeaf6ae5e49fad480 Mon Sep 17 00:00:00 2001 From: Bob Grabar Date: Fri, 14 Dec 2012 16:27:53 -0500 Subject: [PATCH 2/2] remove duplicate 'and' --- source/tutorial/getting-started.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tutorial/getting-started.txt b/source/tutorial/getting-started.txt index d09054af7e2..73e62fe580f 100644 --- a/source/tutorial/getting-started.txt +++ b/source/tutorial/getting-started.txt @@ -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 ` documentation and