Query Rules with Geo Search


I’m trying to investigate the feasibility of the following use case.

A user searches for the following phrase.

hospitals near 48103

If a user types in “near”, anything after that word will be a location.
I will turn that location into coordinates using Google’s Geocoding API.
I then want to add something like 'aroundLatLng' => '42.279594, -83.732124' to my query.

Is there a way to do this with Instant Search or with the API?



It’s not handled by default in InstantSearch but you can use the queryHook function to change the query before it’s sent to Algolia.

This is where you can contact Google’s API and remove “near xxx” from the query.

Please let me know if that would work for you.

1 Like

Thanks @julienbourdeau for your reply!

I think this will work, but my apologies for not being more specific, I know this is possible with instantsearch.js, but is there someething comparable for React InstantSearch? https://community.algolia.com/react-instantsearch/widgets/SearchBox.html I’m not seeing anything that is similar to the queryHook function you mentioned.

Thank you!

I think with React you have to use onSearchStateChange, you should be able to modify the searchState from here.

Let me know if it worked.