MongoDB Full-Text index

Source: Internet
Author: User
Tags create index

Related article: PHP uses Coreseek for full-text indexing

Introduction
Mongo provides some functionality that's useful for text search and tagging.
MongoDB provides some features that are owned for full-text search and tagging.

Multikeys (indexing values in an array) multi-built (indexed value in array)
The Mongo Multikey feature can automatically index arrays of values. Tagging is a good example of where this feature is useful. Suppose you has an article object/document which are tagged with some category names:

obj = { name :  "Apollo" , Text:  "Some text about Apollo moon landings" , //body  Tags: [   "moon" ,  "Apollo" ,  "spaceflight"   //index tag }       

And that this object was stored in Db.articles. The command

Db.articles.ensureIndex ({tags:1});
Would index all the tags in the document, and create index entries for "Moon", "Apollo" and "spaceflight" for that document .

Index Use Example
These items on the usual-in:

>  Print(db.  Articles.  FindOne({ tags:"Apollo"}).  Name);                 

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 is equally expensive.)

Text Search
It is fairly easy to implement basic full text search using Multikeys. What we recommend are have a field that have all of the keywords in it, something like:

{: ' This was fun',:["This","was","Fun"]}  

Your code must split the title above into the keywords before saving. Note that this code (which are 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 ...)

Related article: PHP uses Coreseek for full-text indexing

Reprint Please specify: Fkblog»mongodb full-text index (http://www.fkblog.org/blog485)

MongoDB Full-Text index

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.