Im using Easy-Search package and would like to search posts (or comments to those posts).
The problem: Nothing gets shown when search is typed in. No error messages shown on both console.log and server.
Updates: I did console.log on both the publish and subscribe. So the subscribe returns the console.log on the browser devtools but the publish does not return anything on the server terminal.
Template html
<template name="searchPosts">
{{> esInput id="main" index=indexes placeholder="Search.." }}
{{#esEach index="posts"}}
{{> postItem}}
{{/esEach}}
{{#esEach index="comments"}}
{{> postItem}}
{{/esEach}}
</template>
Template js - client
Template.searchPosts.onCreated(function () {
var self = this, instance;
instance = EasySearch.getComponentInstance(
{ id: 'main', index: 'posts'},
{ id: 'main', index: 'comments'}
);
instance.on('searchingDone', function (searchingIsDone) {
searchingIsDone && console.log('I am done!');
});
instance.on('currentValue', function (val) {
console.log('The user searches for ' + val);
});
this.subscribe("allDocs");
});
Template.searchPosts.helpers({
indexes : function () {
return ['posts', 'comments'];
},
posts: function () {
return Posts.find();
}
});
Have you tried initEasySearch instead of createSearchIndex? I've used this and everything is showing properly:
News.initEasySearch(['title', 'body'], {
'limit': 3,
'use': 'mongo-db',
'returnFields': ['title', 'category', 'slug', 'coverImage', 'publishedAt']
})
This will search the News collection , on the fields title and body, returning those fields below. Then , on the html, i just call {{title}}, and the rest of the fields, because the returnFields are really the things that easySearch subscribe in order to display it on the frontend.
ok, here's a working demo: https://jsfiddle.net/nke3qbxr/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With