Database Reference
In-Depth Information
"_id" : 1
},
"ns" : "test.texttest",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"ns" : "test.texttest",
"name" : "body_text",
"weights" : {
"body" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 1
}
]
Okay, we've enabled text search, created our index, and confirmed that it's there; now let's run our text
search command.
Running the Text Search Command
In the version of MongoDB we are using there is no shell helper for the text command, so we execute it with the
runCommand syntax as follows:
> db.texttest.runCommand( "text", { search :"fish" } )
This command will return any documents that match the query string of "fish" . In this case it has returned two
documents. The output shows quite a bit of debug information, along with a "results" array; this contains a number
of documents. These include a combination of the score for the matching document and the returned, the matching
document as the obj . You can see that the text portions of our matching documents both contain the word fish or
fishing which both match our query! It's also worth noting that MongoDB text indexes are case-insensitive, which is an
important consideration when performing your text queries.
remember that all entries in text search are tokenized and stemmed. this means that words like fishy or
fishing will be stemmed down to the word fish.
Note
In addition, you can see the score, which was 0.75 or 0.666, indicating the relevance of that result to your query— the
higher the value, the better the match. You can also see the stats for the query, including the number of objects
returned (2) and the time taken, which was 112 microseconds.
 
 
Search WWH ::




Custom Search