Make easy search only show data if searched

how can I make easy search only display data if the input already contains text / have searched ?

I don’t really understand the question. Maybe you can add some details or examples?

I guess @mal30 means if you don’t provide search text to easy search, it by default returns everything. It starts to filter when you have search text. Maybe you could check if SearchIndex.count === Collection.count() for not looping the data.

Thanks for responses,

@daveeel i don’t understand, can you give some example ?

i have multiple index

assigmentsIndex = new EasySearch.Index({
collection: coll_assigments,
fields: [‘title’],
engine: new EasySearch.MongoDB()
});
groupsIndex = new EasySearch.Index({
collection: coll_groups,
fields: [‘name’],
engine: new EasySearch.MongoDB()
});

helpers

Template.header.helpers({
searchIndexes: () => [groupsIndex, assigmentsIndex],
groupsIndex: () => groupsIndex,
assigmentsIndex: () => assigmentsIndex
});

and my template

{{> EasySearch.Input indexes=searchIndexes }}
{{#EasySearch.Each index=groupsIndex}}
    {{name}}
{{/EasySearch.Each}}

{{#EasySearch.Each index=assigmentsIndex}}
    {{title}}
{{/EasySearch.Each}}

it returns all documments assigmentsIndex and groupsIndex, I want initially not returns any document until I did a search
@energistic

There seems to be a better solution from official sample than what was in my head.

See: https://github.com/matteodem/easy-search-leaderboard/blob/master/leaderboard.html

Simply put your result in the else block of IfInputEmpty. Let me know if that works.

{{#EasySearch.IfInputEmpty indexes=searchIndexes }}
For example "Grace Gaga"
{{else}} {{#EasySearch.Each index=groupsIndex}} {{name}} {{/EasySearch.Each}} {{#EasySearch.Each index=assigmentsIndex}} {{title}} {{/EasySearch.Each}} {{/EasySearch.IfInputEmpty}}

it works @daveeel but only on the client side, on the server easy search still take all the appropriate document index although I didn’t do a search

Not sure why you have server side concern. The index needs to be created once and update itself with new docs, it’s the job of the package. If you are thinking something deeper, better ask the author in Github.

1 Like