Skip to content

Commit

Permalink
Add geo polygon query type
Browse files Browse the repository at this point in the history
  • Loading branch information
aprudhomme committed Dec 20, 2023
1 parent 003e652 commit 0481f89
Show file tree
Hide file tree
Showing 8 changed files with 1,971 additions and 1,490 deletions.
18 changes: 18 additions & 0 deletions clientlib/src/main/proto/yelp/nrtsearch/search.proto
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,22 @@ message GeoPointQuery {
google.type.LatLng point = 2; // point used to query whether the polygon contains it.
}

// Polygon defined by a list of geo points
message Polygon {
// Points defining the polygon. Coordinates must be in clockwise order, except for holes. Holes must be in counter-clockwise order. The shape is assumed to be closed, with the first point automatically also used as the last point. The polygon must not be self-crossing, otherwise may result in unexpected behavior. Polygons cannot cross the 180th meridian. Instead, use two polygons: one on each side.
repeated google.type.LatLng points = 1;
// Specify holes in the polygon. Hole polygons cannot themselves contain holes.
repeated Polygon holes = 2;
}

// A query that matches documents with geo points within polygons
message GeoPolygonQuery {
// Field in the document to query
string field = 1;
// Geo polygons to search for containing points
repeated Polygon polygons = 2;
}

// A query that matches documents which contain a value for a field.
message ExistsQuery {
string field = 1; // Field in the document to query
Expand Down Expand Up @@ -363,6 +379,7 @@ enum QueryType {
MATCH_PHRASE_PREFIX = 18;
PREFIX = 19;
CONSTANT_SCORE_QUERY = 20;
GEO_POLYGON = 21;
}

// Defines a full query consisting of a QueryNode which may be one of several types.
Expand Down Expand Up @@ -392,6 +409,7 @@ message Query {
MatchPhrasePrefixQuery matchPhrasePrefixQuery = 21;
PrefixQuery prefixQuery = 22;
ConstantScoreQuery constantScoreQuery = 23;
GeoPolygonQuery geoPolygonQuery = 24;
}
}

Expand Down
15 changes: 15 additions & 0 deletions docs/queries/geo_polygon.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Geo-Polygon Query
==========================

A query that matches documents with geo point within a defined set of polygons.

Proto definition:

.. code-block::
message GeoPolygonQuery {
// Field in the document to query
string field = 1;
// Geo polygons to search for containing points
repeated Polygon polygons = 2;
}
43 changes: 42 additions & 1 deletion grpc-gateway/luceneserver.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,23 @@
},
"description": "A query that matches documents with polygon that contains the geo point."
},
"luceneserverGeoPolygonQuery": {
"type": "object",
"properties": {
"field": {
"type": "string",
"title": "Field in the document to query"
},
"polygons": {
"type": "array",
"items": {
"$ref": "#/definitions/luceneserverPolygon"
},
"title": "Geo polygons to search for containing points"
}
},
"title": "A query that matches documents with geo points within polygons"
},
"luceneserverGeoRadiusQuery": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -4243,6 +4260,26 @@
},
"title": "Point representation"
},
"luceneserverPolygon": {
"type": "object",
"properties": {
"points": {
"type": "array",
"items": {
"$ref": "#/definitions/typeLatLng"
},
"description": "Points defining the polygon. Coordinates must be in clockwise order, except for holes. Holes must be in counter-clockwise order. The shape is assumed to be closed, with the first point automatically also used as the last point. The polygon must not be self-crossing, otherwise may result in unexpected behavior. Polygons cannot cross the 180th meridian. Instead, use two polygons: one on each side."
},
"holes": {
"type": "array",
"items": {
"$ref": "#/definitions/luceneserverPolygon"
},
"description": "Specify holes in the polygon. Hole polygons cannot themselves contain holes."
}
},
"title": "Polygon defined by a list of geo points"
},
"luceneserverPrefixQuery": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -4356,6 +4393,9 @@
},
"constantScoreQuery": {
"$ref": "#/definitions/luceneserverConstantScoreQuery"
},
"geoPolygonQuery": {
"$ref": "#/definitions/luceneserverGeoPolygonQuery"
}
},
"description": "Defines a full query consisting of a QueryNode which may be one of several types."
Expand Down Expand Up @@ -4414,7 +4454,8 @@
"MULTI_FUNCTION_SCORE_QUERY",
"MATCH_PHRASE_PREFIX",
"PREFIX",
"CONSTANT_SCORE_QUERY"
"CONSTANT_SCORE_QUERY",
"GEO_POLYGON"
],
"default": "NONE",
"description": "Defines different types of QueryNodes."
Expand Down
Loading

0 comments on commit 0481f89

Please sign in to comment.