Currently, this is only possible with FT.AGGREGATE
. You will have to use APPLY
(documentation here), and then sort by it.
Try something like:
FT.AGGREGATE index "@name:%%burger%%" APPLY "geodistance(@location, -75.153270, 39.949655)" AS distance SORTBY distance ASC
There are some other overloading for geodistance
in the documentation, you can use the one that suits your environment best.
In addition, you should take another look at the GEO filter syntax. Your query is invalid:
Geo filters
As of v0.21, it is possible to add geo radius queries directly into the query language with the syntax @field:[{lon} {lat} {radius} {m|km|mi|ft}]. This filters the result to a given radius from a lon,lat point, defined in meters, kilometers, miles or feet. See Redis' own GEORADIUS command for more details as it is used internally for that).
Radius filters can be added into the query just like numeric filters. For example, in a database of businesses, looking for Chinese restaurants near San Francisco (within a 5km radius) would be expressed as: chinese restaurant @location:[-122.41 37.77 5 km].
The query I suggested will work, but if you can give a relevant radius to look in, you might get better performance.
for example:
FT.AGGREGATE index "@name:%%burger%% @location:[-75.153270 39.949655 5 km]" APPLY "geodistance(@location, -75.153270, 39.949655)" AS distance SORTBY distance ASC
will limit the search to a 5km radius.
Hope that helps!