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

1

13

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

Verda answered 22/4, 2015 at 7:41 Comment(1)
please go through groups.google.com/forum/#!topic/mongodb-user/99t5WXmUUAgMicco
B
2
  • 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)

Benavides answered 29/11, 2016 at 2:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.