Introduction
Mongo provides some functionality that is useful for text search and tagging.
MongoDB提供了一些擁有的功能用于全文搜尋與标記。
Multikeys (Indexing Values in an Array)多建(數組中得索引值)
The Mongo multikey feature can automatically index arrays of values.
Tagging is a good example of where this feature is useful. Suppose you
have an article object/document which is tagged with some category
names:
and that this object is stored in db.articles. The command
db.articles.ensureIndex( { tags: 1 } );
will index all the tags on the document, and create index entries for “moon”, “apollo” and “spaceflight” for that document.
索引使用例子
You may then query on these items in the usual way:
Apollo
The database creates an index entry for each item in the array. Note an
array with many elements (hundreds or thousands) can make inserts very
expensive. (Although for the example above, alternate implementations
are equally expensive.)
Text Search
It is fairly easy to implement basic full text search using multikeys.
What we recommend is having a field that has all of the keywords in it,
something like:
Your code must split the title above into the keywords before saving. Note that this code (which is not part of Mongo DB) could do stemming, etc. too. (Perhaps someone in the community would like to write a standard module that does this…)