Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How textScore field is calculated in mongodb full text search? [duplicate]

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

like image 480
hemkaran_raghav Avatar asked Apr 22 '15 07:04

hemkaran_raghav


People also ask

What is textScore in MongoDB?

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.

How do I search for text in MongoDB?

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.

Which operator performs only logical or searches on text index?

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.


1 Answers

  • Start with exp = 0;
  • Each time the term occurs: if exp = 0, set exp = 1, else set exp = 2 * exp;
  • Increment the frequency by 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)

like image 121
satish chennupati Avatar answered Oct 05 '22 19:10

satish chennupati