$search stage with near to rating and current date and increase score proportional to likes and comment count

I’m working on social media platform and I need to fetch posts for newsfeed with mongodb search query.

currently I’m using dynamic index on my post collection, Let say this my post collection

{
 _id : ObjectId('123'),
 GoogleRating : 4.5,
 LikeCount : 20,
 CommentCount : 10,
 CreatedDate : "2022-04-21T00:00:00.000+00:00"
},
{
 _id : ObjectId('456'),
 GoogleRating : 1,
 LikeCount : 0,
 CommentCount : 5,
 CreatedDate : "2021-12-01T00:00:00.000+00:00"
}

And this is my current search stage

"$search":{
   "compound":{
      "should":[
         {
            "near":{
               "path":"GoogleRating",
               "origin":5,
               "pivot":2,
               "score":{
                  "boost":{
                     "value":2
                  }
               }
            }
         },
         {
            "near":{
               "path":"CreatedDate",
               "origin":"ISODate(""2022-04-21T00:00:00.000Z"")",
               "pivot":7776000000,
               "score":{
                  "boost":{
                     "value":3
                  }
               }
            }
         },
         {
            "near":{
               "path":"LikeCount",
               "origin":1000,
               "pivot":2,
               "score":{
                  "boost":{
                     "value":3
                  }
               }
            }
         },
         {
            "near":{
               "path":"CommentCount",
               "origin":1000,
               "pivot":2,
               "score":{
                  "boost":{
                     "value":3
                  }
               }
            }
         }
      ]
   }
}

I’ve three criteria to boost document score.

  1. Boost score on the basis on GoogleRating.
  2. Boost score on the basis on Current date.
  3. Boost score on the basis of LikeCount and CommentCount.

I need to improve my search result Because it’s not giving me desired output please suggest me what should i need to change in my search stage.

Hi @Waleed_Nasir,

Thanks for providing the search stage details as well as sample documents.

I need to improve my search result Because it’s not giving me desired output please suggest me what should i need to change in my search stage.

Can you provide both the current output as well as the expected / desired output?

In addition to this, if there are more stages to your pipeline, please provide those as well.

Regards,
Jason

Hello @Jason_Tran,
The other stages are just lookup and project stage.
my desired output should be based on recency, popularity on the basis of likes and comment count and google rating which max value is 5.