The "text search" concept in mongodb does not work like that. Instead the concept here is that you define "mutiple fields" in your "text index" and just search for the terms.
Let's say you have "stuff" like this:
{ "_id" : ObjectId("55ba22294bde97b581332979"), "title" : "Hello there" },
{ "_id" : ObjectId("55ba22414bde97b58133297a"), "title" : "Hello world" },
{
"_id" : ObjectId("55ba22594bde97b58133297b"),
"title" : "Hello world",
"suburb" : "melbourne"
}
Then I decide to create a text index like this:
db.junk.createIndex(
{ "title": "text", "suburb": "text" },
{ "weights": { "title": 10 } }
)
Then I do a search using $text
:
db.junk.find(
{ "$text": { "$search": "Hello World Melbourne" } },
{ "score": { "$meta": "textScore" } }
).sort({ "score": { "$meta": "textScore" } })
Which gives the results:
{
"_id" : ObjectId("55ba22594bde97b58133297b"),
"title" : "Hello world",
"suburb" : "melbourne",
"score" : 11.5
},
{
"_id" : ObjectId("55ba22414bde97b58133297a"),
"title" : "Hello world",
"score" : 1.5
},
{
"_id" : ObjectId("55ba22294bde97b581332979"),
"title" : "Hello there",
"score" : 1
}
Which "both" searches over all the fields specified in the index and also considers the additional "weight" as given to the "suburb" field in this case to make it an even more popular ranking.
So you don't use additional conditons in terms, you put "all" of the terms in the "one" text query string to search on multiple fields.