MongoDB text indexing in action

Josh Software - Where Programming is an Art!

Recently, I had a good use-case to use MongoDB text-indexing and I gave it a shot. I found it to be pretty awesome – even though its not have full-fledged text-search engine capabilities (like facets etc.) it does the job for simple text searches.

So, what did we want to do? We had the following model

Now, we had to search for people like “John Doe” or “Jane” or with email “”. I decided to give text indexing a shot.

Some of the salient features of text indexing are tokenizing, stemming and relevance scores. Basically, the words are split using the default token (white space), there is support for multiple languages and each result has a weightage score which tells us how relevant that result was.

Getting Started

To get started, you need to enable text-indexing. You can do this in 2 ways:

Add the following text to your mongod.conf file…

View original post 550 more words