meteorhacks / search-source

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

Searching multiple collections #13

Closed zaklampert closed 9 years ago

zaklampert commented 9 years ago

Hello! This is fantastic.

Is it possible to search multiple collections in one search?

Thank you!

arunoda commented 9 years ago

Yes. it is. It's upto you to define the search definition, either on server or client

zaklampert commented 9 years ago

Should it be as simple as

return [Recipes.find(selector, options).fetch(), Products.find(selector, options).fetch() ]

because that's spitting out a "Modifier must be an object" error.

zaklampert commented 9 years ago

Splitting the queries out like this worked.

 var recipeFind = Recipes.find(selector, options).fetch()
 var productFind = Products.find(selector, options).fetch()

  return  recipeFind, productFind

So cool.

zaklampert commented 9 years ago

Just kidding. It's actually just searching the second query.

zaklampert commented 9 years ago

simply _.extend-ing the two objects worked. like a charm

 var recipeFind = Recipes.find(selector, options).fetch()
    var productFind = Products.find(selector, options).fetch()
    var bothFind = _.extend(recipeFind, productFind)

    return {
        data: bothFind
    }

hooray!