Over a million developers have joined DZone.

Mongoid_fulltext: full-text n-gram search for your MongoDB models

DZone's Guide to

Mongoid_fulltext: full-text n-gram search for your MongoDB models

· Database Zone
Free Resource

MongoDB Atlas is a database as a service that makes it easy to deploy, manage, and scale MongoDB. So you can focus on innovation, not operations. Brought to you in partnership with MongoDB.

Today I wanted to let you know about a very handy library: mongoid_fulltext, an open-source full-text search implementation for your MongoId models in Ruby.




We’ve been using mongoid_search for sometime now for auto-complete. It’s a fine component that splits sentences and uses MongoDB to index them. Unfortunately it doesn’t rank them, so results come in order of appearance. In contrast, mongoid-fulltext uses n-gram matching (with n=3 right now), so we index all of the substrings of length 3 from text that we want to search on. If you search for "damian hurst", mongoid_fulltext does lookups for "dam", "ami", "mia", "ian", "an ", "n h", " hu", "hur", "urs", and "rst" and combines the results to get a most likely match. This also means users can make simple spelling mistakes and still find something relevant. In addition, you can index multiple collections in a single index, producing best matching results within several models. Finally, mongoid-fulltext leverages MongoDB native indexing and map-reduce.


This library is written by @aaw, who implements most of art.sy search technology. All due credit goes entirely to him.

Source: http://code.dblock.org/mongoidfulltext-full-text-n-gram-search-for-your-mongodb-models

MongoDB Atlas is the best way to run MongoDB on AWS — highly secure by default, highly available, and fully elastic. Get started free. Brought to you in partnership with MongoDB.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}