Multiple-pass ranking on geo search

We’d like to use geo search to improve our results ranking, but I’m having a bit of trouble figuring out how to express our ranking model in Algolia.

Our users are searching over product and service “vendors” across the country, and we believe that they’d prefer to see results with the following approximate priority:

  • Vendors with the “local sales” tag within about 100 miles
  • Vendors with the “state sales” tag within their current US state or any immediately neighboring state
  • Vendors with the “national sales” tag (no geo required)
  • Vendors with the “state sales” tag anywhere else in the country
  • All remaining vendors (e.g. those unknown or without tags)

What this amounts to, in plain language, is an answer to the question, “Will this vendor sell me stuff?”

As far as I can reason, this requires making multiple geo queries with different ranges or polygons, and I haven’t figured out quite how that would work in Algolia.

Can you advise on an approach here? We have some amount of flex in our requirements, so suggestions that would accomplish even most of what we want are helpful.

Thank you!

HI @mark5,

I believe you are correct in that you may need to make several separate search queries with the geo search and/or filters and then combine the results in your code. In other words, do a search for each one of the queries in your bulleted lists, save the results and then display the results, one after the other, on your results page.

You may be able to combine some of them using filters or optionalfilters.

Thanks, Cindy! That’s super helpful. I hadn’t noticed optionalFilters, and it looks like those could be particularly useful.

One follow-up question: can geo search be used as an “optionalFilter”? It’d be nice to be able to say: “show results within this bounded area at the top of results, then other results afterwards.” I haven’t had luck doing this in test queries yet, nor have I found specific docs on it, but figured I’d ask just in case I’m simply doing the syntax wrong.

Hi @mark5! Unfortunately geosearch can’t be used as optionalFilters.

When enabling aroundLatLngViaIP, records without _geoloc attribute are not included in the results.

However, there is a workaround to try with attributes:

  • Include _geoloc : Add a fake _geoloc attribute to your records such as either { lat: 0, lng: 0 } or something far like the North Pole { lat: 90, lng: 0 }
  • Expand the radius : Because aroundLatLngViaIP automatically computes a radius, you’ll need to override to get all the results using aroundRadius=all

The other workaround is to make two queries and filter your lists:

  • Get all records with browse and store them in a list
  • Get the geoloc records sorted and store them in a list
  • Filter using custom code and remove from the first list the records present in the second one
  • Append the lists

Relevant Links:

I hope this helps with your use-case!

2 Likes