MongoDB Text Search: Experimental Feature in MongoDB 2.4

MongoDB

#Releases

Text search (SERVER-380) is one of the most requested features for MongoDB 10gen is working on an experimental text-search feature, to be released in v2.4, and we’re already seeing some talk in the community about the native implementation within the server. We view this as an important step towards fulfilling a community need.

MongoDB text search is still in its infancy and we encourage you to try it out on your datasets. Many applications use both MongoDB and Solr/Lucene, but realize that there is still a feature gap. For some applications, the basic text search that we are introducing may be sufficient. As you get to know text search, you can determine when MongoDB has crossed the threshold for what you need.

Setting up Text Search


You can configure text search in the mongo shell:

db.adminCommand( { setParameter : 1, textSearchEnabled : true } )


Or set a command:

mongod --setParameter textSearchEnabled=true

A Simple Example:


In this example, we will insert 3 documents into a collection, add in text indexes and then query for the word “Australian”.

// inserting documents
t.save( { _id: 1, title: "Physics World", caption: "Physics World is the membership magazine of the Institute of Physics."} );
<p>t.save( { _id: 2, title: "A break away!", caption: "'A break away!' is an 1891 painting by Australian artist Tom Roberts."} );</p>
<p>t.save( { _id: 3, title: "Mahim Bora", caption: "Mahim Bora (b.1926) is an Indian writer and educationist from Assam state."});</p>
<p>// this creates an index
t.ensureIndex( { caption: "text" } );</p>
<p>// this executes the search command. The “score” below indicates how many of the search terms appear in the indexed fields of the document and how frequently they appear</p>
<p>t.runCommand( "text", { search : "Australian" } );
=>
{
"queryDebugString" : "australian||||||",
"language" : "english",
"results" : [
{
"score" : 0.55,
"obj" : {
"_id" : 2,
"title" : "A break away!",
"text" : "'A break away!' is an 1891 painting by Australian artist Tom Roberts."
}
}
],
"stats" : {
"nscanned" : 1,
"nscannedObjects" : 0,
"n" : 1,
"timeMicros" : 89
},
"ok" : 1
}

We’ll be organizing a series of project nights through the MongoDB User Group network for anyone interested to come and try out the feature and provide feedback. Here are a list of the upcoming testing sessions:


If you’re interested in organizing a project night for text search get in touch with the community team who can help you get set up. All you need is some computers and a few data sets and you’ll be ready to test.