Skip to content

Commit 9197609

Browse files
ritsthvladvildanov
andcommitted
Fix lat/lon swap in search querystring geo() helper (#4223)
Co-authored-by: Vladyslav Vildanov <[email protected]>
1 parent 14714a0 commit 9197609

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎redis/commands/search/querystring.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def geo(lat, lon, radius, unit="km"):
5757
"""
5858
Indicate that value is a geo region
5959
"""
60-
return GeoValue(lat, lon, radius, unit)
60+
return GeoValue(lon, lat, radius, unit)
6161

6262

6363
class Value:

‎tests/test_search_querystring.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Unit tests for the search query string builders.
2+
3+
These tests exercise the pure-Python query building logic and do not require a
4+
running Redis server, so they live in the ``fixed_client`` test group.
5+
"""
6+
7+
import pytest
8+
9+
from redis.commands.search.querystring import GeoValue, geo, intersect
10+
11+
12+
@pytest.mark.fixed_client
13+
class TestGeoValue:
14+
"""``geo()`` must render longitude before latitude.
15+
16+
RediSearch expects geo filters as ``[lon lat radius unit]``, which is also
17+
the order used by ``GeoValue`` and ``query.GeoFilter``.
18+
"""
19+
20+
def test_geo_renders_longitude_before_latitude(self):
21+
assert geo(lat=51.45, lon=-0.44, radius=10).to_string() == "[-0.44 51.45 10 km]"
22+
23+
def test_geo_matches_geovalue_built_directly(self):
24+
assert (
25+
geo(lat=51.45, lon=-0.44, radius=10).to_string()
26+
== GeoValue(-0.44, 51.45, 10).to_string()
27+
)
28+
29+
def test_geo_keeps_the_requested_unit(self):
30+
assert (
31+
geo(lat=51.45, lon=-0.44, radius=10, unit="mi").to_string()
32+
== "[-0.44 51.45 10 mi]"
33+
)
34+
35+
def test_geo_in_a_query(self):
36+
query = intersect(location=geo(lat=51.45, lon=-0.44, radius=10))
37+
assert query.to_string() == "@location:[-0.44 51.45 10 km]"

0 commit comments

Comments
 (0)