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.
- Boost score on the basis on GoogleRating.
- Boost score on the basis on Current date.
- 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.