Skip to content

Add GEOSEARCH/GEOSEARCHSTORE command#8094

Merged
oranagra merged 1 commit intoredis:unstablefrom
yangbodong22011:feature-geobbox
Dec 12, 2020
Merged

Add GEOSEARCH/GEOSEARCHSTORE command#8094
oranagra merged 1 commit intoredis:unstablefrom
yangbodong22011:feature-geobbox

Conversation

@yangbodong22011
Copy link
Contributor

@yangbodong22011 yangbodong22011 commented Nov 25, 2020

refer: #4417

Syntax:

GEOSEARCH key [FROMMEMBER member] [FROMLOC long lat] [BYRADIUS radius
unit] [BYBOX width height unit] [WITHCORD] [WITHDIST] [WITHASH] [COUNT
count] [ASC|DESC]

GEOSEARCHSTORE dest_key src_key [FROMMEMBER member] [FROMLOC long lat]
[BYRADIUS radius unit] [BYBOX width height unit] [WITHCORD] [WITHDIST]
[WITHASH] [COUNT count] [ASC|DESC] [STOREDIST]

  • Add two types of CIRCULAR_TYPE and RECTANGLE_TYPE to achieve different
    searches
  • Judge whether the point is within the rectangle, refer to:
    geohashGetDistanceIfInRectangle

@itamarhaber itamarhaber linked an issue Nov 30, 2020 that may be closed by this pull request
@itamarhaber itamarhaber added state:needs-doc-pr requires a PR to redis-doc repository state:major-decision Requires core team consensus labels Nov 30, 2020
@yangbodong22011 yangbodong22011 force-pushed the feature-geobbox branch 4 times, most recently from fce6a1d to 075c65c Compare December 1, 2020 05:40
Copy link
Member

@itamarhaber itamarhaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't completed my review yet, but here're a couple of trivialities. Also, looks like some of the additions go well beyond 80-characters-per-line unwritten style guide.

@yangbodong22011 yangbodong22011 changed the title Add GEOBBOX/GEOBBOXBYMEMBER command Add GEOSEARCH/GEOSEARCHSTORE command Dec 4, 2020
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangbodong22011 thank you for this PR.
I think i've reviewed most of the code (excluding the tests).

i have many comments, but i guess the most important one to address to consider if both geohashGetDistanceIfInRectangle is considering the box inside the radius or the one bound is.
hope i'm not talking nonsense.. i didn't study the topic enough and i have to move on. hope you can dismiss my concerns one way or another.

@yangbodong22011
Copy link
Contributor Author

@oranagra Thanks for your review, follow this tcl case, my original idea is as follows:

image

  • The circle is the actual search area of 200 km byradius.
  • The rectangle is the actual search area of 200 km bybox.

Q: How to determine that a point is within the axis-aligned rectangle?

If the coordinates of this point are greater than the minimum latitude and longitude and less than the maximum latitude and longitude.

// x2,y2 is the point, x1, y1 is the search center point. so use x2, y2 and bounds to judge.

int geohashGetDistanceIfInRectangle(double *bounds, double x1, double y1,
                                     double x2, double y2, double *distance) {
     if (x2 <bounds[0] || x2> bounds[2] || y2 <bounds[1] || y2> bounds[3]) return 0;
     *distance = geohashGetDistance(x1, y1, x2, y2);
     return 1;
}

After you suggest that you should use height/2, width/2, I think your opinion is correct and logical.

So in order to reach the search range of the above pictures, the new parameters are as follows:

geosearch Sicily fromloc 15 37 bybox 400 400 km asc

Is that right?

@oranagra
Copy link
Member

oranagra commented Dec 7, 2020

@yangbodong22011 yes, width and height of that box are 400. i'm not aware of a word in English that describes half the width (other than saying half_width), so i guess we need to stick to the terminology of the command syntax, and adjust the code.

@yangbodong22011
Copy link
Contributor Author

updated:

  • Modify the position of the bounds variable and add comments to GeoShape.
  • Modify the calculation method of radius_meters, remove sqrt, ues the larger of height/2 and width/2.
  • GEOSEARCH with STORE|STOREDIST and GEOSEARCHSTORE with STORE means syntax error.
  • Add extractBoxOrReply() for parse box
  • refactor some function name and modify comment

@oranagra I will close some of the comments in your previous comments, please review again when you have time.

oranagra
oranagra previously approved these changes Dec 8, 2020
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangbodong22011 thank you.
can you tell me something about the tests coverage and what was your approach when creating them?
i.e. did you duplicate some of the GEORADIUS tests and changed them to use GEOSEARCH?

I see you attempted to cover some of the syntax errors, but did you also try to test some box specific points? (i.e. search for points that are outside a circle but inside a big that has similar "radius")?
or trying to create odd box shapes (non square ones)?

@oranagra
Copy link
Member

oranagra commented Dec 8, 2020

@redis/core-team please approve the new commands and their syntax.

oranagra
oranagra previously approved these changes Dec 9, 2020
soloestoy
soloestoy previously approved these changes Dec 9, 2020
@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Dec 9, 2020
madolson
madolson previously approved these changes Dec 10, 2020
refer: redis#4417

GEOSEARCH key [FROMMEMBER member] [FROMLOC long lat] [BYRADIUS radius
unit] [BYBOX width height unit] [WITHCORD] [WITHDIST] [WITHASH] [COUNT
count] [ASC|DESC]

GEOSEARCHSTORE dest_key src_key [FROMMEMBER member] [FROMLOC long lat]
[BYRADIUS radius unit] [BYBOX width height unit] [WITHCORD] [WITHDIST]
[WITHASH] [COUNT count] [ASC|DESC] [STOREDIST]

- Add two types of CIRCULAR_TYPE and RECTANGLE_TYPE to achieve different searches
- Judge whether the point is within the rectangle, refer to:
geohashGetDistanceIfInRectangle
@oranagra
Copy link
Member

@yangbodong22011 can you please also make a redis-doc PR for this?

@yangbodong22011
Copy link
Contributor Author

@yangbodong22011 can you please also make a redis-doc PR for this?

sure, I will do it.

@yossigo yossigo added the approval-needed Waiting for core team approval to be merged label Dec 10, 2020
@oranagra oranagra merged commit 4d06d99 into redis:unstable Dec 12, 2020
@oranagra oranagra mentioned this pull request Jan 13, 2021
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Mar 2, 2021
Add commands to query geospatial data with bounding box.

Two new commands that replace the existing 4 GEORADIUS* commands.

GEOSEARCH key [FROMMEMBER member] [FROMLOC long lat] [BYRADIUS radius
unit] [BYBOX width height unit] [WITHCORD] [WITHDIST] [WITHASH] [COUNT
count] [ASC|DESC]

GEOSEARCHSTORE dest_key src_key [FROMMEMBER member] [FROMLOC long lat]
[BYRADIUS radius unit] [BYBOX width height unit] [WITHCORD] [WITHDIST]
[WITHASH] [COUNT count] [ASC|DESC] [STOREDIST]

- Add two types of CIRCULAR_TYPE and RECTANGLE_TYPE to achieve different searches
- Judge whether the point is within the rectangle, refer to:
geohashGetDistanceIfInRectangle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval-needed Waiting for core team approval to be merged release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus state:needs-doc-pr requires a PR to redis-doc repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Query geospatial data with bounding box

7 participants