Skip to content

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

Merged
merged 4 commits into from
Aug 12, 2025
Merged

Add Geo Filtering #704

merged 4 commits into from
Aug 12, 2025

Conversation

sethbuff
Copy link
Collaborator

@sethbuff sethbuff commented Aug 6, 2025

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 have index=True in the Field 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 a GeoFilter object, it will raise an error. I have it just working with the EQ operator but we could technically have it work against any operator. I don't really see any other use case for any other operators.

@sethbuff
Copy link
Collaborator Author

sethbuff commented Aug 6, 2025

@abrookins @slorello89 I would greatly appreciate a review on this! We are looking to implement this in our app ASAP.

Copilot

This comment was marked as outdated.

@bsbodden bsbodden requested review from Copilot and bsbodden August 12, 2025 17:34
Copy link
Contributor

@Copilot Copilot AI left a 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 and GeoFilter 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.
Copy link
Contributor

@bsbodden bsbodden left a 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

@sethbuff
Copy link
Collaborator Author

✅ Approved - Ready to Merge 🚀

Great addition to Redis OM Python! This PR successfully implements geographic filtering capabilities

I appreciate the additions @bsbodden !

@bsbodden bsbodden merged commit b00c9e0 into main Aug 12, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants