Commit 159981e7 authored by qetu3790's avatar qetu3790 Committed by Oran Agra
Browse files

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: default avatarBinbin <binloveplay1314@qq.com>
(cherry picked from commit b2d393b9)
parent ec06e933
...@@ -91,8 +91,8 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) { ...@@ -91,8 +91,8 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) {
* \-----------------/ -------- \-----------------/ * \-----------------/ -------- \-----------------/
* \ / / \ \ / * \ / / \ \ /
* \ (long,lat) / / (long,lat) \ \ (long,lat) / * \ (long,lat) / / (long,lat) \ \ (long,lat) /
* \ / / \ / \ * \ / / \ / \
* --------- /----------------\ /--------------\ * --------- /----------------\ /---------------\
* Northern Hemisphere Southern Hemisphere Around the equator * Northern Hemisphere Southern Hemisphere Around the equator
*/ */
int geohashBoundingBox(GeoShape *shape, double *bounds) { int geohashBoundingBox(GeoShape *shape, double *bounds) {
...@@ -164,14 +164,14 @@ GeoHashRadius geohashCalculateAreasByShapeWGS84(GeoShape *shape) { ...@@ -164,14 +164,14 @@ GeoHashRadius geohashCalculateAreasByShapeWGS84(GeoShape *shape) {
geohashDecode(long_range, lat_range, neighbors.east, &east); geohashDecode(long_range, lat_range, neighbors.east, &east);
geohashDecode(long_range, lat_range, neighbors.west, &west); geohashDecode(long_range, lat_range, neighbors.west, &west);
if (geohashGetDistance(longitude,latitude,longitude,north.latitude.max) if (north.latitude.max < max_lat)
< radius_meters) decrease_step = 1; decrease_step = 1;
if (geohashGetDistance(longitude,latitude,longitude,south.latitude.min) if (south.latitude.min > min_lat)
< radius_meters) decrease_step = 1; decrease_step = 1;
if (geohashGetDistance(longitude,latitude,east.longitude.max,latitude) if (east.longitude.max < max_lon)
< radius_meters) decrease_step = 1; decrease_step = 1;
if (geohashGetDistance(longitude,latitude,west.longitude.min,latitude) if (west.longitude.min > min_lon)
< radius_meters) decrease_step = 1; decrease_step = 1;
} }
if (steps > 1 && decrease_step) { if (steps > 1 && decrease_step) {
......
...@@ -293,6 +293,31 @@ start_server {tags {"geo"}} { ...@@ -293,6 +293,31 @@ start_server {tags {"geo"}} {
test {GEORADIUSBYMEMBER simple (sorted)} { test {GEORADIUSBYMEMBER simple (sorted)} {
r georadiusbymember nyc "wtc one" 7 km r georadiusbymember nyc "wtc one" 7 km
} {{wtc one} {union square} {central park n/q/r} 4545 {lic market}} } {{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)} { test {GEOSEARCH FROMMEMBER simple (sorted)} {
r geosearch nyc frommember "wtc one" bybox 14 14 km r geosearch nyc frommember "wtc one" bybox 14 14 km
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment