summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-05-09 14:13:24 +0100
committerJoram Wilander <jwawilander@gmail.com>2017-05-09 08:13:24 -0500
commit622998add12734a6c2b5d79918338a4d6dca7ce6 (patch)
tree198d507eb04c5684d5b191b17ed957f02f2df6ed /vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go
parentb25021b9129820147bf596b834d438ef218acf28 (diff)
downloadchat-622998add12734a6c2b5d79918338a4d6dca7ce6.tar.gz
chat-622998add12734a6c2b5d79918338a4d6dca7ce6.tar.bz2
chat-622998add12734a6c2b5d79918338a4d6dca7ce6.zip
PLT-6398: Add dependency on go elastic search library. (#6340)
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go')
-rw-r--r--vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go
new file mode 100644
index 000000000..1faaf24e0
--- /dev/null
+++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go
@@ -0,0 +1,72 @@
+// Copyright 2012-present Oliver Eilhard. All rights reserved.
+// Use of this source code is governed by a MIT-license.
+// See http://olivere.mit-license.org/license.txt for details.
+
+package elastic
+
+// GeoPolygonQuery allows to include hits that only fall within a polygon of points.
+//
+// For more details, see:
+// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-geo-polygon-query.html
+type GeoPolygonQuery struct {
+ name string
+ points []*GeoPoint
+ queryName string
+}
+
+// NewGeoPolygonQuery creates and initializes a new GeoPolygonQuery.
+func NewGeoPolygonQuery(name string) *GeoPolygonQuery {
+ return &GeoPolygonQuery{
+ name: name,
+ points: make([]*GeoPoint, 0),
+ }
+}
+
+// AddPoint adds a point from latitude and longitude.
+func (q *GeoPolygonQuery) AddPoint(lat, lon float64) *GeoPolygonQuery {
+ q.points = append(q.points, GeoPointFromLatLon(lat, lon))
+ return q
+}
+
+// AddGeoPoint adds a GeoPoint.
+func (q *GeoPolygonQuery) AddGeoPoint(point *GeoPoint) *GeoPolygonQuery {
+ q.points = append(q.points, point)
+ return q
+}
+
+func (q *GeoPolygonQuery) QueryName(queryName string) *GeoPolygonQuery {
+ q.queryName = queryName
+ return q
+}
+
+// Source returns JSON for the function score query.
+func (q *GeoPolygonQuery) Source() (interface{}, error) {
+ // "geo_polygon" : {
+ // "person.location" : {
+ // "points" : [
+ // {"lat" : 40, "lon" : -70},
+ // {"lat" : 30, "lon" : -80},
+ // {"lat" : 20, "lon" : -90}
+ // ]
+ // }
+ // }
+ source := make(map[string]interface{})
+
+ params := make(map[string]interface{})
+ source["geo_polygon"] = params
+
+ polygon := make(map[string]interface{})
+ params[q.name] = polygon
+
+ var points []interface{}
+ for _, point := range q.points {
+ points = append(points, point.Source())
+ }
+ polygon["points"] = points
+
+ if q.queryName != "" {
+ params["_name"] = q.queryName
+ }
+
+ return source, nil
+}