Sending a search query without widgets in instant search

I am able to build a basic search page using the search widget like below (I am using instantsearch.min.js ). However on the same page I need to programmatically query the algolia.

Please advice how I can do this. I would like to stick with instantsearch.min.js and not use algoliasearch.min.js

search.addWidget(
instantsearch.widgets.refinementList({
    container: '#initiative-container',
    attributeName: 'field_initiative',
    operator: 'or',
    templates: {
        header: 'Initiative'
    }
})

);

Thank you,
Vishal

However on the same page I need to programmatically query the algolia

Can you describe wht you mean? InstantSearch is responsible for searching in Algolia’s index. What do you want to do that didn’t work?

Hi @julienbourdeau,
I want to search the Algolia Index. The input will not come from the user it will come from my js frontend script. My search is a contextual search not a event based user search.

After reading your docs I understand I need to implement my own search widget and I got it to work for a basic query. However I need to use a addDisjunctiveFacetRefinement which I am unable to implement due to lack of documentation.

Please see this line in the code which is not working me hence I had to comment it out.

helper.addDisjunctiveFacetRefinement(‘field_main_customer’,‘Netflix’).search();

// binding the input search
var customWidget = {
getConfiguration: function(searchParams) {
    return {
    };
},
init: function(options) {
    const helper = options.helper;
    const input = 'Netflix';
    // helper.addDisjunctiveFacetRefinement('field_main_customer','Netflix').search(); // I want to use Disjuntive Facet this is not working for me
    helper.setQuery(input).search();
},
render: function(options) {
}
};
searchCustomerStory.addWidget(customWidget);

Thank you,
Vishal

Hi @julienbourdeau,
Also I need to keep my script ( not the user ) will keep on initiating the search depending on the context.

So How does one use helper.search(); in Instant search.

There is alot of documentation for basic search but not instant search.

Thank you,
Vishal

Hi @julienbourdeau,

I also created a jsfiddle for you https://jsfiddle.net/vishalkhialani/Ly3rppf4/1/

Hope this helps.Please see line 26.

Thank you,
Vishal

To use facet, you need to use the exact value that are in your records. For example, if you’re faceting using the brand attribute which contains a value nike then you need to use the exact same value nike in addDisjunctiveFacetRefinement. Using a value that is not in your dataset will yield 0 results, which seems to be the case here.

You could use setQuery to do a more classical search, which would be more permissive but will be based on your searchable attributes.

Hi @Bobylito,
I am using the exact value. I am sure of it. See line 22 . I am using your data set here so it shoudd be familiar for your to debug.

https://jsfiddle.net/vishalkhialani/Ly3rppf4/1/

Thank you,
Vishal

Hi @Bobylito,
I apologise the issue was I have to add the fields as Attributes for faceting in the dashboard.

Its working now.

Thank you,
Vishal

2 Likes