From 0cf73169b2a52ada49e2c444bd8f7988e5b4ed16 Mon Sep 17 00:00:00 2001 From: Abhi Dangeti Date: Wed, 12 Jul 2023 12:33:11 -0600 Subject: [PATCH] Add top level query redirects for GeoShape queries (#1841) --- query.go | 25 +++++++++++++++++++++++++ search_test.go | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/query.go b/query.go index 4f1f136ce..3385ed779 100644 --- a/query.go +++ b/query.go @@ -225,3 +225,28 @@ func NewGeoDistanceQuery(lon, lat float64, distance string) *query.GeoDistanceQu func NewIPRangeQuery(cidr string) *query.IPRangeQuery { return query.NewIPRangeQuery(cidr) } + +// NewGeoShapeQuery creates a new Query for matching the given geo shape. +// This method can be used for creating geoshape queries for shape types +// like: point, linestring, polygon, multipoint, multilinestring, +// multipolygon and envelope. +func NewGeoShapeQuery(coordinates [][][][]float64, typ, relation string) (*query.GeoShapeQuery, error) { + return query.NewGeoShapeQuery(coordinates, typ, relation) +} + +// NewGeoShapeCircleQuery creates a new query for a geoshape that is a +// circle given center point and the radius. Radius formats supported: +// "5in" "5inch" "7yd" "7yards" "9ft" "9feet" "11km" "11kilometers" +// "3nm" "3nauticalmiles" "13mm" "13millimeters" "15cm" "15centimeters" +// "17mi" "17miles" "19m" "19meters" If the unit cannot be determined, +// the entire string is parsed and the unit of meters is assumed. +func NewGeoShapeCircleQuery(coordinates []float64, radius, relation string) (*query.GeoShapeQuery, error) { + return query.NewGeoShapeCircleQuery(coordinates, radius, relation) +} + +// NewGeometryCollectionQuery creates a new query for the provided +// geometrycollection coordinates and types, which could contain +// multiple geo shapes. +func NewGeometryCollectionQuery(coordinates [][][][][]float64, types []string, relation string) (*query.GeoShapeQuery, error) { + return query.NewGeometryCollectionQuery(coordinates, types, relation) +} diff --git a/search_test.go b/search_test.go index c8330bfea..1c9163100 100644 --- a/search_test.go +++ b/search_test.go @@ -2154,7 +2154,7 @@ func TestGeoShapePolygonContainsPoint(t *testing.T) { coordinates: []float64{1.5, 48.2}, }, } { - q, err := query.NewGeoShapeQuery( + q, err := NewGeoShapeQuery( [][][][]float64{{{test.coordinates}}}, geo.PointType, "contains",