Instantsearch.js: Allow search from custom function

Created on 12 Jan 2018  路  2Comments  路  Source: algolia/instantsearch.js

This is not a bug, but rather a feature request of some sorts.

I'd like to see the possibility to manually trigger a search from a custom function. So let's say you have your regular index with categories. Now, it would be neat to have a custom function (not attached to instantsearch) to call a category from a custom function.

Simply put, something that works like this:

<a href="javascript:;" data-category="catname" class="link">Test-Link</a>

$(".link").on("click", function(){
    var targetCategory = $(this).data("category");
    // search current index from targetCategory
})

For some projects, we don't need a list of categories but rather single links. This would come handy. Or, if that kind of function is not possible, at least have the possibility to fill the search input with the value and trigger a search.

Question

Most helpful comment

The last option would work, I guess. Got me into the right direction... haven't done much with the helper yet but seems to be what I'm looking for. Thanks.

All 2 comments

You have different API available to achieve such behaviour:

  • You can use the connectors to implement your own widget. You will have the full control of what is render without the need to reimplement all the logic of the widgets. But you are still tight to InstantSearch.

  • You can also create a full custom widget, you will have access to helper instance. The helper is the internal tool that we used to track the state of the search. Again you are still tight to InstantSearch.

  • Last option you can also get the helper reference from the InstantSearch instance if you don't want to be tight to it. You can retrieve the helper instance like this:

const search = instantseach(...);

search.start();

search.helper // You can do whatever you want with it

The last option would work, I guess. Got me into the right direction... haven't done much with the helper yet but seems to be what I'm looking for. Thanks.

Was this page helpful?
0 / 5 - 0 ratings