Paul Hiles
Paul Hiles

Reputation: 9788

Azure Search Distance filter with variable distance

Suppose I have the following scenario:

A search UI to allow individuals to find plumbers who are able to service their home location.

When a plumber enters their info into the system, they provide their coordinates and a maximum distance they are willing to travel.

The individual can then enter their home coordinates and should be presented with a list of plumbers who are eligible.

Looking at the Azure Search geo.distance function, I cannot see how to do this. Scenarios where the searcher provides a distance are well covered but not where the distance is different for each search record.

The documentation provides the following example:

$filter=geo.distance(location, geography'POINT(-122.131577 47.678581)') le 10

This works correctly but if I try and change the 10 to the maxDistance field, it fails with

Comparison must be between a field, range variable or function call and a literal value

My requirement seems fairly basic but am now wondering if this is currently possible with Azure Search?

Upvotes: 2

Views: 287

Answers (2)

Eugene Shvets
Eugene Shvets

Reputation: 4671

To add to Paul's answer, one possible workaround is to use a conservatively large constant value instead of referencing the maxDistance field in your $filter expression. Then, you can filter the resulting list of plumbers on the client to take each plumber's max distance into account and produce final list of plumbers.

Upvotes: 1

Paul Hiles
Paul Hiles

Reputation: 9788

I found an azure feedback suggestion asking for this feature but no news on if/when it will be implemented. Therefore it is safe to assume that this scenario is not currently supported.

Upvotes: 1

Related Questions