{"id":14706,"date":"2014-07-11T22:10:39","date_gmt":"2014-07-11T16:40:39","guid":{"rendered":"https:\/\/2thenew.today\/blog\/?p=14706"},"modified":"2014-07-11T22:10:39","modified_gmt":"2014-07-11T16:40:39","slug":"a-level-ahead-with-text-search-in-mongodb","status":"publish","type":"post","link":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/","title":{"rendered":"A level ahead with text search in mongoDb"},"content":{"rendered":"<p>In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work.<\/p>\n<p><strong>Document Scoring<\/strong><br \/>\nMongoDB assigns a score to each of the document that contains the search term passed in $text field. The higher the score, the more relevant that document would be to that search term.<\/p>\n<p><strong>Stemming<\/strong><br \/>\nMongoDb full text search only matches the complete stemmed words. For those who don\u2019t know what stemming is, it is a process of reducing a word to its stem\/root. For example:walked, walking, walks.<\/p>\n<p>All of the above words have a stem word walk. Stemming is language dependent and that is why MongoDb supports quite a bit of languages which have their own set of stop words and stemmers defined.<\/p>\n<p><strong>Create Compound Text Indexes<\/strong><br \/>\nMongoDb allows us to create compound text indexes, lets see how we can do that:<\/p>\n<p><code>db.article.ensureIndex({ 'title' : 'text', 'content': 'text' });<\/code><\/p>\n<p>In the above command, we have created text index on more then one fields, i.e., title and text fields of the article collection.<\/p>\n<p>When creating compound indexes, we can assign individual weights to the fields to increase their ranking in the search results. Weights can be assigned as follows while creating indexes:<\/p>\n<p><code>db.article.ensureIndex({ 'title' : 'text', 'content': 'text' }, {weights: {title: 5}});<\/code><\/p>\n<p>In the above statement, we have assigned the title a weight of 5, while the content field gets the default weight of 1. So, if a search match is found in title and content fields, the documents with title match will have higher ranking due to the assigned weight.<\/p>\n<p>We can also apply projection to the $text queries and get only the required fields just like normal projections.<\/p>\n<p><strong>Multiple Language Support<\/strong><br \/>\nMongoDb supports a handful of text search languages, we can define the default language for a text index so that MongoDB uses relevant stemmers and stop words. This can be done as follows:<\/p>\n<p><code>db.article.ensureIndex({'title': 'text'}, {'default_language': 'french'});<\/code><\/p>\n<p>You can find the list of languages supported as of now <a href=\"http:\/\/docs.mongodb.org\/manual\/core\/index-text\/\">here<\/a>.<\/p>\n<p>I hope this helps you in understanding the Free text search from MongoDB. We should see even more features related to search in the upcoming releases of the database. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document [&hellip;]<\/p>\n","protected":false},"author":65,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":7,"footnotes":""},"categories":[1],"tags":[1479,4843,1230,4846,1478,972],"class_list":["post-14706","post","type-post","status-publish","format-standard","hentry","category-technology","tag-compound-index","tag-database","tag-indexing","tag-mongodb","tag-stemming","tag-text-search"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Sakshi Tyagi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"A level ahead with text search in mongoDb | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"A level ahead with text search in mongoDb | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#article\",\"name\":\"A level ahead with text search in mongoDb | TO THE NEW Blog\",\"headline\":\"A level ahead with text search in mongoDb\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2014-07-11T22:10:39+05:30\",\"dateModified\":\"2014-07-11T22:10:39+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#webpage\"},\"articleSection\":\"Technology, compound index, Database, indexing, MongoDB, stemming, text search\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#listItem\",\"name\":\"A level ahead with text search in mongoDb\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#listItem\",\"position\":3,\"name\":\"A level ahead with text search in mongoDb\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/\",\"name\":\"Sakshi Tyagi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Sakshi Tyagi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/\",\"name\":\"A level ahead with text search in mongoDb | TO THE NEW Blog\",\"description\":\"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-level-ahead-with-text-search-in-mongodb\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"datePublished\":\"2014-07-11T22:10:39+05:30\",\"dateModified\":\"2014-07-11T22:10:39+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"A level ahead with text search in mongoDb | TO THE NEW Blog","description":"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document","canonical_url":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#article","name":"A level ahead with text search in mongoDb | TO THE NEW Blog","headline":"A level ahead with text search in mongoDb","author":{"@id":"https:\/\/2thenew.today\/blog\/author\/sakshi\/#author"},"publisher":{"@id":"https:\/\/2thenew.today\/blog\/#organization"},"datePublished":"2014-07-11T22:10:39+05:30","dateModified":"2014-07-11T22:10:39+05:30","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#webpage"},"isPartOf":{"@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#webpage"},"articleSection":"Technology, compound index, Database, indexing, MongoDB, stemming, text search"},{"@type":"BreadcrumbList","@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog#listItem","position":1,"name":"Home","item":"https:\/\/2thenew.today\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/2thenew.today\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#listItem","name":"A level ahead with text search in mongoDb"},"previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#listItem","position":3,"name":"A level ahead with text search in mongoDb","previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/2thenew.today\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/2thenew.today\/blog\/"},{"@type":"Person","@id":"https:\/\/2thenew.today\/blog\/author\/sakshi\/#author","url":"https:\/\/2thenew.today\/blog\/author\/sakshi\/","name":"Sakshi Tyagi","image":{"@type":"ImageObject","@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g","width":96,"height":96,"caption":"Sakshi Tyagi"}},{"@type":"WebPage","@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#webpage","url":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/","name":"A level ahead with text search in mongoDb | TO THE NEW Blog","description":"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/2thenew.today\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/#breadcrumblist"},"author":{"@id":"https:\/\/2thenew.today\/blog\/author\/sakshi\/#author"},"creator":{"@id":"https:\/\/2thenew.today\/blog\/author\/sakshi\/#author"},"datePublished":"2014-07-11T22:10:39+05:30","dateModified":"2014-07-11T22:10:39+05:30"},{"@type":"WebSite","@id":"https:\/\/2thenew.today\/blog\/#website","url":"https:\/\/2thenew.today\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/2thenew.today\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"A level ahead with text search in mongoDb | TO THE NEW Blog","og:description":"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document","og:url":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/","og:image":"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"A level ahead with text search in mongoDb | TO THE NEW Blog","twitter:description":"In our previous post, we saw how simply we could use the free text search feature from MongoDB. In continuation to that, in this post we would be looking at how can we create multiple text indexes and understand how actually the things work. Document Scoring MongoDB assigns a score to each of the document","twitter:image":"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"14706","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 08:00:24","updated":"2024-02-29 10:43:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.today\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.today\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tA level ahead with text search in mongoDb\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/2thenew.today\/blog"},{"label":"Technology","link":"https:\/\/2thenew.today\/blog\/category\/technology\/"},{"label":"A level ahead with text search in mongoDb","link":"https:\/\/2thenew.today\/blog\/a-level-ahead-with-text-search-in-mongodb\/"}],"_links":{"self":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/posts\/14706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/comments?post=14706"}],"version-history":[{"count":0,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/posts\/14706\/revisions"}],"wp:attachment":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/media?parent=14706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/categories?post=14706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/tags?post=14706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}