Javascript hook to change sort


I have two sort indexes on my instantsearch magento 2 page. I want to pick one of these sort indexes by frontend javascript code, instead of a user selecting the sort select button (which is hidden).

It should actually be triggered when the user changes a filter. For example: if the user defines a price range I want to sort it by price (it’s actually a different filter, but comparable)

If I look on the events/hooks ( ) I do not really see any events which are triggered when changing filters where I could subscribe to.

Will a help in this case? Or are there other ways to solve this?

Found a post where is described what I want: Custom ranking "scores" for attributes

Easy way
When your user is making a search, you could try to spot in your front-end relevant keywords such as “music”, “photography”, etc. and route the algolia query to the corresponding index.
The is rather easy to implement, but you will not be able to handle typos like musci, and such.

But I have no idea how to “route the algolia query to the corresponding index” ?

Hope somebody can help me with that?

Found a solution. We are using a customized instantsearch.js and there I could override the searchFunction in instantsearchOptions.

// check the facet value
if ( Array.isArray(helper.state.disjunctiveFacetsRefinements.product_materials) ) {       
    let m = helper.state.disjunctiveFacetsRefinements.product_materials[0].slice(-1).toLowerCase();
    let newIndex = algoliaConfig.indexName + '_products_material_'+m+'_rank_asc';      
    // and if the index for this chosen facet is available use it
    if ( window.algoliaConfig.sortingIndices.findIndex( index => === newIndex )>=0 ) {
        helper.state.index = newIndex