Theres many posts, each post has many comments. Search shows post items (correct) but also duplicates (wrong). The duplicates are likely from comments that fit the search query, but are only able to appear as empty post items. Comments are connect to the postId of each posts.
Qns: How do I merge the results to only show post items (with no duplicates)? Looking at docs, seems like I need transform function but im not sure how to tweak it and merge results.
Below is a diagram to explain.
my futile attempt to do the adjustments
postsIndex = new EasySearch.Index({
collection : Posts,
fields : [ 'message', 'title'],
engine : new EasySearch.MongoDB()
});
commentsIndex = new EasySearch.Index({
collection : Comments,
fields : ['body'],
engine : new EasySearch.MongoDB({
transform: function(doc) {
return Comments._transform(doc);
}
})
})
});
I think instead of adjusting your search results to fit the needed format, you should have another collection that contains the searchable dataas you want it to receive. Something like view models.
Theres many posts, each post has many comments. Search shows post items (correct) but also duplicates (wrong). The duplicates are likely from comments that fit the search query, but are only able to appear as empty post items. Comments are connect to the postId of each posts.
Qns: How do I merge the results to only show post items (with no duplicates)? Looking at docs, seems like I need transform function but im not sure how to tweak it and merge results.
Below is a diagram to explain.
my futile attempt to do the adjustments