I want to know how MongoDB is calculating the score of the text in full text search.
Like if I will search for samsung note edge
in followings:
Samsung Galaxy Note Edge
Samsung Galaxy Note 4
Samsung Galaxy S6 Edge
Samsung Galaxy Note 4 duos
Samsung Z
Full text Search as follows:
db.mobiles.find({
$text : {$search : "samsung note edge"}
}, {
score : {$meta : "textScore" }
}).sort({
score : {$meta : "textScore" }
})
Is giving me result as follows:
{
name : "Samsung Galaxy Note Edge",
score: 1.875000
},
{
name : "Samsung Galaxy Note 4",
score: 1.250000
},
{
name : "Samsung Galaxy S6 Edge",
score: 1.250000
},
{
name : "Samsung Galaxy Note 4 duos",
score: 1.200000
},
{
name : "Samsung Z",
score: 0.750000
}
The results are different if I will search for Samsung edge
Description. "textScore" Returns the score associated with the corresponding $text query for each matching document. The text score signifies how well the document matched the search term or terms. Starting in MongoDB 4.4, must be used in conjunction with a $text query.
Use the $text query operator to perform text searches on a collection with a text index. $text will tokenize the search string using whitespace and most punctuation as delimiters, and perform a logical OR of all such tokens in the search string.
If the search string is a space-delimited string, $text operator performs a logical OR search on each term and returns documents that contains any of the terms.
exp = 0
;if exp = 0, set exp = 1, else set exp = 2 * exp
;1/exp
.So, in fact, you are right that there is a sum of a geometric series here. If a term occurs k times, then the freq of the term (which is more like a score than a frequency, but it's called freq in the struct) will be
1 + 1/2 + ... + (1/2)^(k - 1) = (1 - (1/2)^k)/(1 - 1/2) = 2 * (1 - 1/2^k)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With