-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(search): Add GEO index and RADIUS search #5854
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
base: main
Are you sure you want to change the base?
Conversation
b9f3a30
to
a1a5f6a
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.
Looks good so far 👍🏻
src/core/search/search.cc
Outdated
|
||
IndexResult Search(const AstGeoNode& node, string_view active_field) { | ||
DCHECK(!active_field.empty()); | ||
double converted_radius = GeoIndex::ConvertToRadiusInMeters(node.radius, node.unit); |
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.
I'd make the index do that internally
e54ccac
to
0c89126
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.
Looks valid so far
struct AstGeoNode { | ||
AstGeoNode(double lat, double lon, size_t radius, std::string unit); | ||
double lat, lon; | ||
size_t radius; | ||
std::string unit; | ||
}; |
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.
TODO: parse unit from lexer (so we can throw the error in time)
src/core/search/indices.cc
Outdated
double lat; | ||
if (!absl::SimpleAtod(coordinates[0], &lat)) | ||
return false; | ||
|
||
double lon; | ||
if (!absl::SimpleAtod(coordinates[1], &lon)) | ||
return false; | ||
|
||
entry index_entry = std::make_pair(point{lat, lon}, id); | ||
|
||
rtree_->insert(index_entry); | ||
|
||
return true; |
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.
Just style comment how to reduce volume 😅
// absl::StrSplit can split into a pair but you can't check there easily
double lon, lat;
if (!absl::SimpleAtod() || !absl::SimpleAtod())
return false;
rtree_->emplace(point{}, id)
return true;
src/core/search/indices.cc
Outdated
double lat; | ||
if (!absl::SimpleAtod(coordinates[0], &lat)) { | ||
return std::nullopt; | ||
} | ||
|
||
double lon; | ||
if (!absl::SimpleAtod(coordinates[1], &lon)) { | ||
return std::nullopt; | ||
} | ||
|
||
return point{lat, lon}; | ||
} |
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.
Just style comment, feel free to ignore 😅
double lon, lat;
if (!absl::SimpleAtod() || !absl::SimpleAtod())
return nullopt;
src/core/search/indices.h
Outdated
std::vector<DocId> GetAllDocsWithNonNullValues() const override { | ||
return std::vector<DocId>{}; | ||
} |
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.
That need to be for a @geofield:*
query? Is this possible? If not, we should explicitly disallow it. Not saying to solve it now, just a TODO would help us not to forget
src/core/search/indices.cc
Outdated
} | ||
} | ||
|
||
std::optional<GeoIndex::point> GeoIndex::GetGeoPoint(const DocumentAccessor& doc, |
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.
Can be in anonymous namespace
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.
Well, you can improve the rules by making proxy objects and making fewer composable rules out of them. I'm sure it can be done. Yet... it will be more code I assume. Not sure, I mean you have to admit it doesn't look really sexy 🙄
Fixes #4536 Signed-off-by: mkaruza <mario@dragonflydb.io>
567e33c
to
33518a2
Compare
33518a2
to
8d6c4dc
Compare
Fixes #4536