Skip to main content

Full Text search in MongoDB

Full text search is similar to content search from entire database or from storage where data is located. It is something similar to how we search any content in any search application by entering certain string keywords or phrases and getting back the relevant results sorted by their ranking. This is common requirement in any large data-set application for quick and efficient searching method. 

This post I am sharing about text search from MongoDB database. Text search option is available in almost every database either RDBMS family or NoSQL family.  Mongodb have something different that is ranking (weight of attributes). Starting from version 2.4, MongoDB began with an experimental feature supporting Full-Text Search using Text Indexes. This feature has now become an integral part of the product. The Text Search uses streaming techniques to look for specified words in the string fields by dropping stop words like a, an, the, etc. 

What are the features of  "Mongodb Full Text Search" ?

• Full-text search as an index type when creating new indexes, just like any other.
• Support for advanced queries, similar to the Google search syntax e.g. negation and phrase matching.
• Indexing of multiple fields, with weighting to give different fields higher priority.
Supports 15 different languages.

What are the steps to configure full text search in mongodb ?

1.Enabling Text Search
2.Creating Text Index
3.Using Text Index

Configure or enable full text at database level ?
We need to enable manually in MongoDB 2.4. but later version it is by default enable when we install.
in MongoDB configuration file specify with:

setParameter=textSearchEnabled=true
or 
>db.adminCommand({setParameter:true,textSearchEnabled:true})

For this we need to create index for all possible attributes like below

db.collection_name.createIndex(
    {
        company_name: 'text',
        job_description: 'text',
        job_title: 'text',
    },
    {
        weights: {
            company_name: 10,
            job_description: 5,
            job_title: 1
        }
    }
)

Here weight is to specify the ranking of text in result set.


Now use this syntax to search from collection

db. collection_name.find( { $text: { $search: "engineer" } } )

for OR condition
db. collection_name.find( { $text: { $search: "engineer", $search: "mobile" } } )

for AND condition
db. collection_name.find({$text :{$search: "engineer android mobile -developer"}

Now enjoy the quick search and efficient from big data in your application.

Thanks for reading
Plz dont forget to like Facebook Page..
https://www.facebook.com/pages/Sql-DBAcoin/523110684456757

Comments

Post a Comment

Plz dont forget to like Facebook Page..
https://www.facebook.com/pages/Sql-DBAcoin/523110684456757

Popular posts from this blog

History of MySQL from AB Corp to Cloud Database

MySQL was created by a Swedish company, MySQL AB, founded by David Axmark, Allan Larsson and Michael "Monty" Widenius. Original development of MySQL by Widenius and Axmark began in 1994. The first version of MySQL appeared on 23 May 1995. Its name is a combination of "My", the name of co-founder Michael Widenius's daughter,and "SQL", the abbreviation for Structured Query Language. ·          23 May 1995 - First internal release ·          Year 1996 - Version 3 o     Simple CRUD operations o     January 1997 Windows version was released on 8 January 1998 for Windows 95 and NT o     production release 1998, from www.mysql.com ·          Year 2002 - Version 4 o     MyISAM o     unions o     Tracking o     B-trees o     s...

How to add an article in Transactional Replication

If we have a set-up of Transactional Replication for Data Distribution running and wanting to add new object to replication on other server we can follow below process. To add an article In Transaction replication with PUSH Subscription 

Configure Impersonation Authentication in IIS8 for MVC Application

Impersonation is when ASP.NET executes code in the context of an authenticated and authorized client. By default, ASP.NET does not use impersonation and instead executes all code using the same user account as the ASP.NET process, which is typically the ASPNET account. There are 5 below steps by which we can establish Impersonation configuration in our secured application environment. 1.)    Creation of Application/Proxy user where Application is hosted. 2.)    Give appropriate access to the user. 3.)    Create Database Login user on database. 4.)    Authenticate User and provide credential on IIS. 5.)    Then Configure web.config on Application.