Hello,
At another time I needed to get posts similar to a specific one in the blog I'm developing, and this similarity is governed by the tags used in each post. Using MongoDB, I did this by creating an index on the tags, like this:
db.mypostscollection.createIndex({"tags": "text"});
And it works fine, I search for similar ones like this:
MyPostModel.find({
$text: {
$search: tags.replace(/\,/, ' ')
}
}, {
score: {
$meta: "textScore"
}
})
.sort({
score: {
$meta: "textScore"
}
})
However, now you need to fetch the posts by their titles and content, and I thought of doing the following:
db.mypostscollection.createIndex({"title":"text","subtitle":"text","mainContentText":"text"});
But since I already created the $ text index I can not do it again.
So how do I create searches independently? One for the tags, another for the match content.
Thank you in advance.