diff options
author | qetu3790 <qetu3790@163.com> | 2022-02-21 14:06:58 +0800 |
---|---|---|
committer | Oran Agra <oran@redislabs.com> | 2022-04-27 16:31:52 +0300 |
commit | 159981e73c35f5eae262a684203cbf8593ce868d (patch) | |
tree | ce4d0e7703167e703cfc6a0071d46190a8e2cde4 | |
parent | ec06e933198fd46e4a3a936b25a5c40ab05d20f1 (diff) | |
download | redis-159981e73c35f5eae262a684203cbf8593ce868d.tar.gz |
Fix geo search bounding box check causing missing results (#10018)
Consider the following example:
1. geoadd k1 -0.15307903289794921875 85 n1 0.3515625 85.00019260486917005437 n2.
2. geodist k1 n1 n2 returns "4891.9380"
3. but GEORADIUSBYMEMBER k1 n1 4891.94 m only returns n1.
n2 is in the boundingbox but out of search areas.So we let search areas contain boundingbox to get n2.
Co-authored-by: Binbin <binloveplay1314@qq.com>
(cherry picked from commit b2d393b9902fd159878a2f94632853db52e220b8)
-rw-r--r-- | src/geohash_helper.c | 20 | ||||
-rw-r--r-- | tests/unit/geo.tcl | 25 |
2 files changed, 35 insertions, 10 deletions
diff --git a/src/geohash_helper.c b/src/geohash_helper.c index fec193e8b..f8c8209a6 100644 --- a/src/geohash_helper.c +++ b/src/geohash_helper.c @@ -91,8 +91,8 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) { * \-----------------/ -------- \-----------------/ * \ / / \ \ / * \ (long,lat) / / (long,lat) \ \ (long,lat) / - * \ / / \ / \ - * --------- /----------------\ /--------------\ + * \ / / \ / \ + * --------- /----------------\ /---------------\ * Northern Hemisphere Southern Hemisphere Around the equator */ int geohashBoundingBox(GeoShape *shape, double *bounds) { @@ -164,14 +164,14 @@ GeoHashRadius geohashCalculateAreasByShapeWGS84(GeoShape *shape) { geohashDecode(long_range, lat_range, neighbors.east, &east); geohashDecode(long_range, lat_range, neighbors.west, &west); - if (geohashGetDistance(longitude,latitude,longitude,north.latitude.max) - < radius_meters) decrease_step = 1; - if (geohashGetDistance(longitude,latitude,longitude,south.latitude.min) - < radius_meters) decrease_step = 1; - if (geohashGetDistance(longitude,latitude,east.longitude.max,latitude) - < radius_meters) decrease_step = 1; - if (geohashGetDistance(longitude,latitude,west.longitude.min,latitude) - < radius_meters) decrease_step = 1; + if (north.latitude.max < max_lat) + decrease_step = 1; + if (south.latitude.min > min_lat) + decrease_step = 1; + if (east.longitude.max < max_lon) + decrease_step = 1; + if (west.longitude.min > min_lon) + decrease_step = 1; } if (steps > 1 && decrease_step) { diff --git a/tests/unit/geo.tcl b/tests/unit/geo.tcl index 3aa8f4d56..ccac86b34 100644 --- a/tests/unit/geo.tcl +++ b/tests/unit/geo.tcl @@ -293,6 +293,31 @@ start_server {tags {"geo"}} { test {GEORADIUSBYMEMBER simple (sorted)} { r georadiusbymember nyc "wtc one" 7 km } {{wtc one} {union square} {central park n/q/r} 4545 {lic market}} + + test {GEORADIUSBYMEMBER search areas contain satisfied points in oblique direction} { + r del k1 + + r geoadd k1 -0.15307903289794921875 85 n1 0.3515625 85.00019260486917005437 n2 + set ret1 [r GEORADIUSBYMEMBER k1 n1 4891.94 m] + assert_equal $ret1 {n1 n2} + + r zrem k1 n1 n2 + r geoadd k1 -4.95211958885192871094 85 n3 11.25 85.0511 n4 + set ret2 [r GEORADIUSBYMEMBER k1 n3 156544 m] + assert_equal $ret2 {n3 n4} + + r zrem k1 n3 n4 + r geoadd k1 -45 65.50900022111811438208 n5 90 85.0511 n6 + set ret3 [r GEORADIUSBYMEMBER k1 n5 5009431 m] + assert_equal $ret3 {n5 n6} + } + + test {GEORADIUSBYMEMBER crossing pole search} { + r del k1 + r geoadd k1 45 65 n1 -135 85.05 n2 + set ret [r GEORADIUSBYMEMBER k1 n1 5009431 m] + assert_equal $ret {n1 n2} + } test {GEOSEARCH FROMMEMBER simple (sorted)} { r geosearch nyc frommember "wtc one" bybox 14 14 km |