Geo-Searching with 'any location' results included

Hi Friends,

We’re working on a search feature which includes a location + distance from location filter. Some of our records don’t have a location associated to them, but are instead “Any Location”, i.e. no matter what location you search for, we want to include these results.

Does anyone know of a way to do this? One solution we thought of was making 2 separate queries, combining results and rolling our own client side pagination. But we really like using Algolia’s pagination, and would like to keep it as simple as possible.

Thanks in advance.

1 Like

A solution I tried unsuccessfully was to use a disjunctive facet for the any_city boolean on my records combined with the geo-search. However, I think the relationship between the geo-search results and the facet was AND instead of OR.

Does anyone know if you can do geo-searching disjunctively with a filter?

Hi @chenhan22! Thanks for posting your question, sorry it’s taken us a bit to get back to you.

This reminded me of how Algolia Places lets you combine Places results with other results inside of an autocomplete, but there’s no extra pagination support, the example just shows a few top results.

I’ve pinged our dev team about this to see if they have an answer about whether you can do disjunctive faceting with geo, or if there is another way. We’ll get back to you soon.

A geo search will always disregard any record that doesn’t have any geolocation information (i.e. an _geoloc attribute). You cannot therefore get both geolocated and non-geolocated records returned in the same API response.

The workaround is to use two queries, one geo search and one regular search. Merging hits between queries is always tricky, but ranking information (obtained via the getRankingInfo parameter) can make it a lot easier. Pagination will still have to be handled manually, though.

1 Like

Hi there, is there any progress on this? I have the same issue and the 2 solutions I found are either add all the possible locations to the records (it works for me because I only have locations in the US, but it requires de-duplication of records with distinct) or your solution.

I am not really satisfied with any, because the first one will eat a lot of resources and is not really scalable (what happens when I roll out to Europe? Asia?), and the second solution seems unmaintainable and clumsy: I don’t have knowledge of the internals. Could this solution be implemented inside the Algolia javascript SDK by engineers (like you) who know Algolia’s innards?


1 Like