Open lorensr opened 9 years ago
This is already there. You can define the source in the client too. see: https://github.com/meteorhacks/search-source#defining-data-source-in-the-client
I'm sorry, I don't think that's what I'm talking about? If it is, I don't understand how to use it in this way. What I'm suggesting is this:
both:
Items = new Meteor.Collection('items')
server:
SearchSource.defineSource 'search-items', (search, options) ->
query =
match:
name:
query: search
fuzziness: 'AUTO'
operator: 'and'
result = EsClient.search
index: 'myapp'
type: 'items'
body: {query}
data = result.hits.hits.map (doc) ->
source = _.clone doc._source
source._score = doc._score
source
{data}
Meteor.publish 'items', ->
Items.find name: 'Dave'
client:
Meteor.subscribe 'items'
ItemSearch = new SearchSource 'search-items', fields, options
ItemSearch.search 'Bob'
ItemSearch.search 'Alice'
ItemSearch.search 'Eve'
and then instead of ItemSearch.getData
, I do Items.findOne({name:'Alice'})
. And I can also do Items.findOne({name:'Dave'})
.
It would need some way to tell SearchSource
to merge with Items._collection
. Maybe add an option:
ItemSearch = new SearchSource 'search-items', fields, {mergeWith: Items}
I've edited my last comment to also show the publish + subscribe.
Let me know if part of that doesn't make sense :)
@lorensr @arunoda Me too facing the same issue. Im having a set of "items" in search result. But updating an item is not getting reflected in the search result. Do i need to do anything in "Meteor.publish". Please guide me to make it workable.
This would be a great feature:
If my ES type, for example
items
, is a mirror of a Mongo collectionItems
, it would be great ifSearchSource
could add the search results to the local clientItems._collection
so that I can doItems.find x
and get results that were either published OR found through an ES search.