Text Index AND options


In the “Text Index” lecture, it was given that if separate words are searched together then “OR” clause is going to be used internally.

And it was told that if we are searching the words together (like AND clause) then we have to apply metascore but it is misconducting.

db.textexample.insertOne({ statement: “MongoDB is the best” })
db.textexample.insertOne({ statement: “MongoDB is the second” })
db.textexample.insertOne({ statement: “MongoDB is the best best” })
db.textexample.insertOne({ statement: “XYZ is the best best best best best best best best best best best best” })
db.textexample.createIndex({ statement: “text” })

After that, if I try to find “MongoDB best” then results are misconducting since the item which has the best score does not include the “MongoDB” word.

db.textexample.find({$text: { $search: “MongoDB best” }}, {score: {$meta: “textScore”}})
{ “_id” : ObjectId(“5c6a5ea90c93cae53e854701”), “statement” : “MongoDB is the second”, “score” : 0.75 }
{ “_id” : ObjectId(“5c6a5ea50c93cae53e854700”), “statement” : “MongoDB is the best”, “score” : 1.5 }
{ “_id” : ObjectId(“5c6a5eb10c93cae53e854702”), “statement” : “MongoDB is the best best”, “score” : 1.9166666666666665 }
{ “_id” : ObjectId(“5c6a5efa0c93cae53e854704”), “statement” : “XYZ is the best best best best best best best best best best best best”, “score” : 1.922607421875 }

Therefore, I believe, it cannot be recommended to use meta-score to search a pair of words together to imitate “AND” behavior, this is wrong.

@ Ahmet_Fuat_08799

I’m afraid that you did not understand the Lecture fully. As shown, the $meta option merely returns the score value for the search elements. In the Lecture, as it happens, the score value for the two documents means that if you sort by the score, you will get what you want. It does NOT mean that the text index now is using AND instead of OR.

If you look in detail at your example and display the scores, you will see that, because you have ‘best’ repeated multiple times in one document, that document always will get the highest score – so in this case, the score value doesn’t do you any good.

I understood fully and am just specifying that the audience can misunderstand the content since the given example is misleading.

The issue was finding out the words together.
The lecturer is saying “To address the issue we can project the special textScore,” it can be understood "if you want to find the words together like “MongoDB best”, then you can use the score option. The score option can be used for different purposes, like TF/IDF. It cannot be used to search the words together. I will not use it unless I know the whole data. On that example in the lecture, it worked since the data is appropriate for that.