iron router - Meteor: How to implement text search on a collection along with other find queries in Meteor? -
i have app , users can create own private notes.
i trying implement search function these notes.
notes stored in collection schema:
note = threadid: params.threadid date: date userid: user._id, html: params.html in router (using iron-router) use data function return users note data page:
notes.find({threadid: @params._id}) then in jade iterate on note , show them
each notes +note but want include search function user can search own notes.
i want search html field of each note. want filter notes threadid field.
basically this
notes.find({threadid: @params._id}).search('test', field: {html: true}) which finds notes specific threadid field, , searches html field of notes query term 'test'
and once find them, how update page new data?
--------------------------------------update -----------------------------------------
so got searching working, loose reactivity on notes. kind of bummer. looking better way this.
notes = notes.find({threadid: @researchthread._id}, {sort: {date: -1}}) $('#notes-container').empty() notes.foreach (note) -> if note.html.indexof("philosophy") > -1 renderedtemplate = ui.renderwithdata template.note, note ui.insert renderedtemplate, $('#notes-container')[0]
you can use regular expression ($regex) in selector
notes = notes.find({ threadid: @researchthread._id, html: {$regex: 'philosophy'} }, { sort: {date: -1} }) update
to make reactive, need deps.autorun
deps.autorun -> notes = notes.find({ threadid: @researchthread._id, html: {$regex: 'philosophy'} }, { sort: {date: -1} }) /* put render things here */ update
the api changed, used tracker.autorun instead
Comments
Post a Comment