Algolia's instantsearch.js won't work with Meteor


#1

I’ve successfully synced my collection with Algolia, now I want to create a client to search and return results. Algolia has the perfect library, instantsearch.js , for the client side but it won’t work.

If anyone has experience with this please let me what you did to get it to work. Thank you!


#2

Never mind, I found the solution.
[Update] Instantsearch does not support Blaze. Hence, very limited use cases.


#3

How did you get this working? I’ve been looking to leverage algolia… an instantsearch.js package would be cool


#4

Here’s the solution he’s referring to:


#5

@a.com In adddition to the DOMContentLoaded event, you need to use a Mustache template string instead of adding the template to your HTML file with a script tag.

I made a two step tutorial/repo on how to use Instantsearch.js with Meteor.
Here’s the link: https://github.com/yonidej/Meteor-Instantsearch.js

But you should be able to follow their official tutorial with these two edits.


#6

I used the onRendered callback instead of DOMContentLoaded and that worked just fine. Also no need for template strings. You can use Blaze alright to render you templates. Just use it like this:

Template.someTemplate.onRendered( function() {
  search.addWidget(
    instantsearch.widgets.hits({
      container: '#hits',
      hitsPerPage: 10,
      templates: {
        item: (data) => Blaze.toHTMLWithData(Template.yourPreviewTemplate, data),
        empty: Blaze.toHTML(Template.noResults)
      }
    })
  );
});

That makes it a lot cleaner in my opinion. Just my 2cents…