Fix geo search bounding box check causing missing results#10018
Fix geo search bounding box check causing missing results#10018oranagra merged 6 commits intoredis:unstablefrom
Conversation
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.
|
Hi, @qetu3790 I think the current result is within the normal error range (Currently I cannot calculate the distance error of Redis GEO, and the document does not mention it). |
|
The larger the search radius, the greater the error. See the other two examples: 127.0.0.1:6379>` geoadd k1 -4.95211958885192871094 85 n1 11.25 85.0511 n2 127.0.0.1:6379> geoadd k1 -45 65.50900022111811438208 n1 90 85.0511 n2 By the way, I wonder if the geo commands are designed to be used only for small search radius. And what are the boundaries? |
|
@yangbodong22011 isn't this because of the bent trapezoid issue we realized in #8094? |
|
actually, it was here: #8445 |
|
In most cases, the fix cat let search areas contain boundingbox. Although sometims it can't(see the following example), we can also prove the search areas contain all points within the search radius. The example: GEOADD k1 -1 65.9 n2 GEORADIUSBYMEMBER k1 n2 1252357.8 m In this example, the east edge of search areas is also smaller than the ease edge of boundingbox when we have modifed the code. We don't want to decrease more steps, because this can let us compare more points. It's enough as long as search areas contain all points within the search radius. The fix can also solve another problem: crossing pole problem. The crossing pole problem example: 127.0.0.1:6379> geoadd k1 45 65 n1 -135 85.05 n2 |
|
@qetu3790 Going back to the question, in the case you constructed, it is true that the |
no, trapezoid is only used to exclude the search areas that are useless. |
|
Yes. In order to get right results, we have to do so. And I've tried not to decrease |
Co-authored-by: Binbin <[email protected]>
When the latitude is not too high, we still have a large error. Example: 127.0.0.1:6379> geoadd k1 -45 65.50900022111811438208 n1 90 70 n2 |
|
@qetu3790 Can you add several tests you provide to `tests/unit/geo.tcl' ? |
@oranagra please have a look when you have time, merging this PR will make some case search results more accurate. The impact is that |
oranagra
left a comment
There was a problem hiding this comment.
@yangbodong22011 isn't this because of the bent trapezoid issue we realized in #8445? in which case, isn't the proposed fix correct?
no, trapezoid is only used to exclude the search areas that are useless.
This is exactly the trapezoid problem.
the old code used to compare the "horizontal" and "vertical" distance from the point (longitude,latitude), to the lon min/max and lat min/max of north, south, east, and west.
i.e. the horizontal distance was computed only at the center of that box.
from longitude,latitude to east.longitude.max,latitude and to west.longitude.min,latitude.
along a single latitude (the center).
the new code uses the min/max values computed by geohashBoundingBox which has this diagram:
* \-----------------/ -------- \-----------------/
* \ / / \ \ /
* \ (long,lat) / / (long,lat) \ \ (long,lat) /
* \ / / \ / \
* --------- /----------------\ /---------------\
* Northern Hemisphere Southern Hemisphere Around the equator
clearly the central latitude is wrong to use.
instead geohashBoundingBox uses the top / bottom latitudes.
|
@oranagra Yes, agree and thank you for your explanation. |
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 <[email protected]> (cherry picked from commit b2d393b)
Consider the following example:
n2 is in the boundingbox but out of search areas.So we let search areas contain boundingbox to get n2.