Tim Tim - 1 year ago 109
Javascript Question

Algolia Geo Search not seeing ranking info

I'm trying to set up a working geo seach with Algolia.

So far I'm stunned how easy it was to set up. The next thing I'm trying to implement is to show the distance from the found object to the user-selected location.

I'm using instantsearch.js with places.js.

This is my set up for instantsearch:

let search = instantsearch({
appId: 'appid',
apiKey: 'apikey',
indexName: 'dev_index',
url_sync: true,
searchFunction: function(helper) {
helper.setQueryParameter('getRankingInfo', 1).search();

And the places widget (it's called different than in the documentation because I'm pulling it in via NPM)

container: '#places-box',
type: 'city',
aroundLatLngViaIP: false,
countries: 'de'

If I look into the dev tools, I see the following query parameters after selecting a town in the places.js widget:

enter image description here

But my hits object doesn't contain the expected "_rankingInfo" object:

enter image description here

What am I doing wrong?

Answer Source

helper passed to searchFunction is not able to set additional query parameters.

To make it work you can use it like this:

searchFunction: function(helper) {
    this.helper.setQueryParameter('getRankingInfo', true);


It'll do the trick.

jsFiddle: https://jsfiddle.net/ur6qetp1/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download