0
Hello,
At another time I needed to get posts similar to a specific blog I’m developing, and this similarity was governed by the tags used in each post. Using Mongodb, I achieved this by creating an index in the tags, thus:
db.mypostscollection.createIndex({"tags": "text"});
And it works well, I do the search for similar like this:
MyPostModel.find({
$text: {
$search: tags.replace(/\,/, ' ')
}
}, {
score: {
$meta: "textScore"
}
})
.sort({
score: {
$meta: "textScore"
}
})
However, now you need to search the posts by their titles and content, and I thought I’d do it this way:
db.mypostscollection.createIndex({"title":"text","subtitle":"text","mainContentText":"text"});
But as I already created the index $text I can’t do it again.
So how do I create searches independently? One for tags, one for match content.
Thanks in advance.