meteorhacks / search-source

Reactive Data Source for Search
MIT License
145 stars 33 forks source link

Integration with reywood:publish-composite package #46

Closed vladejs closed 8 years ago

vladejs commented 9 years ago

Maybe this is a dumb question, but i saw in the examples there is a transformDoc property which can be used to modify the docs.

Is there a way to skip this and return a publish function instead?

I have a Collection named post which has a postThumbnail property, which is a reference to a document in Files.files collection. I return every post thumbnail using publishComposite publication on server, so it will be awesome if instead of returning a cursor, i could specify a named publication, something like:

SearchSource.defineSource('posts', function(searchText, options) {
    // ...
    return namedPublication('allposts' , searchText , options); 
});

Meteor.publishComposite('allposts', function(searchText, options){
  return {
    find : function(){ return Posts.find(); },
    children : [
    {
       find: function(post){ 
           if (!post.adThumbnail) return;
           return Files.files.find({_id:post.adThumbnail});
       }
    }
    ]
  }
});

I know problem can be solved using transformDoc but who knows, maybe this is possible.

vladejs commented 9 years ago

Actually, i think transformDoc can be used only clientside, so its not a solution to my problem.

Any idea of how to return other collection along to the one iam searching on? (reference models)

vladejs commented 8 years ago

I answer myself. You can return everything you need on the client within the metadata property, like so:

SearchSource.defineSource('posts', function(searchText, options) {
    // ...
    return {
        data : Collection.find(selector,options).fetch(),
        metadata: {
            images : Files.files.find().fetch()
            imagesCount : Files.files.find().count()
            collectionCount : Collection.find(selector,options).count() 
        }
    }
});