That’s an interesting use case, though I am not sure to get the rationale behind it. If I understood correctly, you wish to have a per-record radius. That would be a kind of measurement of the “geographical importance” of the record? A kind of “area of influence”? For example, you could retrieve small towns around you, as well as bigger cities farther away, but not both small and far away towns?
Whatever the reason, there is no way to achieve that out of the box with Algolia. I can think of two workarounds, however:
Query the maximum radius, then filter out records based on their radius. You can know what is each record’s distance to the target location by passing
getRankingInfo=true and examining the
_rankingInfo.geoDistance field of each hit. The problem with this approach is that, if there are many hits with a small radius, you would need to retrieve a lot of them. That’s why I would recommend the second approach:
Perform multiple queries with varying
aroundRadius then merge them. Each query would have a numeric filter on the custom radius field to ensure that only records with that radius are retrieved. Again,
getRankingInfo should allow you to meaningfully compare ranking across the various queries (provided that the only varying parameter is
aroundRadius). It’s a bit more work, but would probably be a lot more efficient. That would be my recommendation.
What do you think?