Reputation: 13323
I am using algolia for search in WordPress. I want to get all the search query like search parameters, search facets after it renders the search result.
To achieve this I am doing something like this
var search = instantsearch({
appId: algolia.application_id,
apiKey: algolia.search_api_key,
indexName: algolia.indices.searchable_posts.name,
urlSync: {
mapping: {'q': 's'},
trackedParameters: ['query']
},
searchParameters: {
facetingAfterDistinct: true,
highlightPreTag: '__ais-highlight__',
highlightPostTag: '__/ais-highlight__'
}
});
search.on('render', () => {
console.log(search.searchParameters.query);
});
It only showing the initial search query. But when I am trying to update the search it is not showing the updated one also. It is also not returning any facet filters searched attributes. So can someone tell me how to get those values after search has been rendered?
Upvotes: 0
Views: 827
Reputation: 13323
I got the solution by going through the documentation. So after the search has been done it renders the result through helper method. So to get all the search query and filters what was used you need to do this
search.helper.on('result', function(event) {
//To get search query
console.log(event._state.query);
//To get search parameters like filters
console.log(event._state.disjunctiveFacetsRefinements);
});
Upvotes: 1