Contact us now for a free tech consultation +5492235066274

A Simple Autocomplete Index Project

About Full Text Search

Nowadays it’s very common to have a search feature in any website or app. This usually happens with platforms that have lots of information to offer to their users. From e-commerce websites which have thousands of products in different categories, to blogs or news sites which have thousands of articles. Whenever a client/user/reader reaches this kind of websites, they automatically tend to find a search box where they can type a query to get to the specific article/product/whatever they’re looking for. Having a bad search engine leads to frustrated users which will most probably never come back to our websites again.

Full text search powers all those search boxes you use daily in websites to find the stuff you look for. Whenever you want to find that batman phone case in the Amazon products database, or when you search for cats playing with laser lights videos on Youtube. Of course this huge websites rely on many other things that power up their search engines, but the base of all searches is full text indexes. That said, let’s see what this post is about.

MongoDB Limitations

If you quickly do a google search for MongoDB full text you’ll find in the MongoDB docs that full text search is supported. So why would we bother learning a new complex technology like Elastic Search, and why would we want to introduce a new complexity into our system architecture? Let’s have a look at MongoDB text search support to find out the reasons.

I will assume you already have MongoDB installed and that you know the basics of it. If that’s the case, then go ahead and open a console and run the mongo command to access the MongoDB console and create a database called fulltext.

$ mongo
$ use fulltext
  switched to db fulltext

Our test database will store articles, so let’s add a collection which we’ll call articles.

$ db.createCollection('articles')
  '{ "ok" : 1 }'

Now let’s add a few documents that will be useful to test. We’ll insert articles with a title and a paragraph as content. I’ve taken some paragraphs from two articles in the New York Times Dealbook.

Original article reference: Yahoo’s Sale to Verizon Leaves Shareholders With Little Say