Search using Meteor

Hi, I have trouble figuring out how to make this.

I have a search bar in the header of the page and below that I have one container with rows and cols where I output project boxes(name, title, price, image, tags)…

I want to achieve searching in that way that when user types some keywords in the search bar(title) that meteor searches all database, generates pagination and display that projects with pagination.

I hope that you understand. I need an idea of how to make this.

Thanks.

Do the results need to be reactive?

Maybe a ternary for each field? value.length > 0 ? { field: value}: { }

It would be the best if they can be, yes.

The basic way is to just have a publication that takes a keyword, you can then either do a regex query or a full text query on the collection. Use a template level subscription and use a session variable or reactive var to store the search query, use the input/keyup event on your input element to change the session/reactive var, which will change the subscription, and update the results on your page.

2 Likes

If you want to include search in a production quality meteor app I would recommend that you use something that is built for searching. I would implement elasticsearch. It is built strictly for searching whereas meteor is built for a lot of things but not necessarily searching.

I would recommend meteorhacks:search-source

2 Likes

Hi @wedranb

Have you got to implement a satisfactory solution to your problem? I have the same problem to be fixed, nonetheless have been disappointed about the difficulty to properly implement a working solution…

I tried both Elastic Search plugin, as well the Search-Source. Couldn’t get it to work though… :confused:

1 Like

I got search-source to work but without pagination.

Now I got it all to work :wink:

how did you do pagination?

I used the limit and skip options parameters in MongoDB. It works quite well. A bit complicated to implement but I believe it’s better than using any package or so…

First I pass the page nr as query params, i.e. mypage.com?q=meteor&page=3
So the page=3 here sets the publication as {limit: x, skip: (3-1*)x}, x being the nr of items you choose to show in a page. Of course if no page query param is set, I set it as 1, so it becomes (1-1=0) to skip.

If you have questions, feel free to ask!

1 Like

Hello, I’m trying to do the same thing. I want to use elasticsearch to search my collection. I have the elastic search code written in js. I need to use the input from meteor to run the search(reactive search).
Can you tell me how to do that?