matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
437 stars 68 forks source link

merge duplicate results - search in 2 collection indexes #485

Closed mervynteo closed 8 years ago

mervynteo commented 8 years ago

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. image

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); 
         }
})
   })
 });
matteodem commented 8 years ago

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.