-
Notifications
You must be signed in to change notification settings - Fork 122
Add Geo Filtering #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Geo Filtering #704
Conversation
@abrookins @slorello89 I would greatly appreciate a review on this! We are looking to implement this in our app ASAP. |
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds geo filtering capabilities to the Redis OM library, enabling spatial queries on coordinate fields using Redis's FT.SEARCH with geo filters. The implementation uses pydantic-extra-types' Coordinate type with custom validators and serializers to handle Redis's coordinate format requirements.
Key Changes:
- Adds
Coordinates
type andGeoFilter
class for spatial queries with radius-based filtering - Implements automatic GEO field indexing for Coordinate-typed fields
- Extends query resolution to support geo filter operations
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pyproject.toml | Adds pydantic-extra-types dependency and bumps version |
aredis_om/model/types.py | Defines Coordinates type with Redis format handling and GeoFilter class |
aredis_om/model/model.py | Implements geo field detection, indexing, and query resolution |
aredis_om/init.py | Exports new Coordinates and GeoFilter types |
tests/test_json_model.py | Adds comprehensive test coverage for geo filtering with JsonModel |
tests/test_hash_model.py | Adds comprehensive test coverage for geo filtering with HashModel |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Add comprehensive docstrings to GeoFilter class with usage examples - Add coordinate validation (longitude: -180 to 180, latitude: -90 to 90) - Add radius validation (must be positive) - Add from_coordinates() convenience class method - Improve error messages with actual invalid values - Add return type hints for better type safety - Add clarifying comments in tests about distance calculations These improvements address GitHub Copilot suggestions and enhance the robustness and usability of the geographic filtering feature.
82472c4
to
b2f37a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Approved - Ready to Merge 🚀
Great addition to Redis OM Python! This PR successfully implements geographic filtering capabilities
I appreciate the additions @bsbodden ! |
This PR adds the ability to use
FT.SEARCH
with a Geo Filter to filter objects based on a specific Radius.To store the coordinates, I used the
pydantic-extra-types
Coordinate
type. This did not align with how Redis expected the coordinates to be stored so I added a validator and a serializer to account for that.When generating the index, I have it checking for the type to see whether it should be indexed as a GEO field. Any fields that want to search using radius must have the field typed as a
Coordinates
type and haveindex=True
in theField
object.When searching, it also checks for the field type to know that it needs to use a
GeoFilter
to search. If the search value is not aGeoFilter
object, it will raise an error. I have it just working with theEQ
operator but we could technically have it work against any operator. I don't really see any other use case for any other operators.