Skip to content

Commit ecae79f

Browse files
author
Bob Grabar
committed
DOCS-797 review edits
1 parent 261431a commit ecae79f

File tree

2 files changed

+40
-69
lines changed

2 files changed

+40
-69
lines changed

source/tutorial.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Development Patterns
5555
tutorial/create-an-auto-incrementing-field
5656
tutorial/enforce-unique-keys-for-sharded-collections
5757
tutorial/aggregation-examples
58+
tutorial/perform-full-text-search
5859

5960
.. index:: tutorials; application development
6061
.. index:: application tutorials
Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,65 @@
1-
========================
2-
Perform Full-Text Search
3-
========================
1+
==================
2+
Search on Keywords
3+
==================
44

55
.. default-domain:: mongodb
66

7-
Mongo uses :ref:`multi-key indexes <index-type-multi-key>` to provide
8-
for searches on text and tags. A multi-key index can index an array of
9-
values.
10-
11-
Text Search
12-
-----------
13-
14-
To implement a text search:
15-
16-
1. Create an array of search words.
17-
18-
2. Create a :ref:`multi-key index <index-type-multi-key>` on the array.
7+
To set up searches based on keywords, create an array field in
8+
your documents and add the keywords as strings in the array. You
9+
can then create a :ref:`multi-key index <index-type-multi-key>` on the
10+
array and create queries that search the array's values.
1911

2012
.. example::
2113

22-
Create an array with all the keywords to search on. Here is a simple example:
23-
24-
.. code-block:: javascript
25-
26-
{ title : "breakfast drinks" ,
27-
keywords : [ "tea" , "coffee" , "juice", "Tang" ]
28-
}
29-
30-
Create a multi-key index on the ``keywords`` array:
31-
32-
.. code-block:: javascript
33-
34-
db.menu.ensureIndex( { keywords: 1 } )
35-
36-
Tagging
37-
-------
38-
39-
To implement a tag search:
40-
41-
1. Create an array of tags.
14+
Suppose you have a collection of library volumes that you want to
15+
make searchable by topics. For each volume, you add the array
16+
``topics``, and you add as many keywords as needed for a given
17+
volume.
4218

43-
2. Create a :ref:`multi-key index <index-type-multi-key>` on the array.
44-
45-
.. example::
46-
47-
Suppose you have documents in the ``articles`` database and the
48-
documents are tagged with category names, such as the following
49-
document:
19+
For the ``Moby-Dick`` volume you might have the following document:
5020

5121
.. code-block:: javascript
5222

53-
{
54-
name: "Apollo" ,
55-
text: "The Apollo program was the first to land
56-
people on the Moon." ,
57-
tags: [ "moon", "apollo", "spaceflight" ]
23+
{ title : "Moby-Dick" ,
24+
author : "Herman Melville" ,
25+
published : 1851 ,
26+
ISBN : 0451526996 ,
27+
topics : [ "whaling" , "allegory" , "revenge" , "American" ,
28+
"novel" , "nautical" , "voyage" , "Cape Cod" ]
5829
}
5930

60-
Create a multi-key index on the ``tags`` array:
31+
You then create a multi-key index on the ``topics`` array:
6132

6233
.. code-block:: javascript
6334

64-
db.articles.ensureIndex( { tags: 1 } )
35+
db.volumes.ensureIndex( { topics: 1 } )
6536

66-
The above command indexes all the strings in the ``tags`` array. For
67-
the document shown in this example, the command creates index entries
68-
for the tags ``moon``, ``apollo`` and ``spaceflight``. Users can query
69-
on those tags. For example:
37+
The multi-key index creates separate index entries for each keyword in
38+
the ``topics`` array. For example the index contains one entry for
39+
``whaling`` and another for ``allegory``.
7040

71-
.. code-block:: javascript
41+
You then queries based on the keywords. For example:
7242

73-
print(db.articles.findOne( { tags : "apollo" } ).name)
43+
.. code-block:: javascript
7444

75-
The database creates an index entry for each item in the array. An
76-
array with many elements (hundreds or thousands) might make inserts very
77-
expensive. Although, for the example above, alternate implementations
78-
are equally expensive.
45+
print(db.volumes.findOne( { topics : "voyage" } ).title)
7946

80-
Comparison to Full-Text Search Engines
81-
--------------------------------------
47+
.. note:: An array with many elements (hundreds or thousands) will incur
48+
greater insert costs.
8249

83-
MongoDB makes certain search full-text searches easy, though differs from
84-
dedicated full-text search engines:
50+
Limitations of Keyword Indexing
51+
-------------------------------
8552

86-
Dedicated full-text engines provide the following:
53+
MongoDB makes keyword search easy, though differs from dedicated
54+
full-text search engines. Dedicated full-text engines provide the
55+
following:
8756

88-
- Built-in text stemming
57+
- Built-in text stemming.
8958

90-
- Ranking of queries matching various numbers of terms. This can be done with
91-
MongoDB but requires user supplied code to do so.
59+
- Ranking of queries matching various numbers of terms. This can be done
60+
with MongoDB but requires user supplied code to do so.
9261

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

0 commit comments

Comments
 (0)