-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathsearch_queries_geo_bounding_box_test.go
126 lines (118 loc) · 3.66 KB
/
search_queries_geo_bounding_box_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// 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
import (
"encoding/json"
"testing"
)
func TestGeoBoundingBoxQuery(t *testing.T) {
q := NewGeoBoundingBoxQuery("pin.location")
q = q.TopLeft(40.73, -74.1)
q = q.BottomRight(40.01, -71.12)
q = q.Type("memory")
src, err := q.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"geo_bounding_box":{"pin.location":{"bottom_right":[-71.12,40.01],"top_left":[-74.1,40.73]},"type":"memory"}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}
func TestGeoBoundingBoxQueryWithGeoPoint(t *testing.T) {
q := NewGeoBoundingBoxQuery("pin.location")
q = q.TopLeftFromGeoPoint(GeoPointFromLatLon(40.73, -74.1))
q = q.BottomRightFromGeoPoint(GeoPointFromLatLon(40.01, -71.12))
src, err := q.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"geo_bounding_box":{"pin.location":{"bottom_right":[-71.12,40.01],"top_left":[-74.1,40.73]}}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}
func TestGeoBoundingBoxQueryWithGeoHash(t *testing.T) {
q := NewGeoBoundingBoxQuery("pin.location")
q = q.TopLeftFromGeoHash("dr5r9ydj2y73")
q = q.BottomRightFromGeoHash("drj7teegpus6")
src, err := q.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"geo_bounding_box":{"pin.location":{"bottom_right":"drj7teegpus6","top_left":"dr5r9ydj2y73"}}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}
func TestGeoBoundingBoxQueryWithWKT(t *testing.T) {
q := NewGeoBoundingBoxQuery("pin.location")
q = q.WKT("BBOX (-74.1, -71.12, 40.73, 40.01)")
src, err := q.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"geo_bounding_box":{"pin.location":{"wkt":"BBOX (-74.1, -71.12, 40.73, 40.01)"}}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}
func TestGeoBoundingBoxQueryWithMixed(t *testing.T) {
q := NewGeoBoundingBoxQuery("pin.location")
q = q.TopLeftFromGeoPoint(GeoPointFromLatLon(40.73, -74.1))
q = q.BottomRightFromGeoHash("drj7teegpus6")
src, err := q.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"geo_bounding_box":{"pin.location":{"bottom_right":"drj7teegpus6","top_left":[-74.1,40.73]}}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}
func TestGeoBoundingBoxQueryWithParameters(t *testing.T) {
q := NewGeoBoundingBoxQuery("pin.location")
q = q.TopLeftFromGeoHash("dr5r9ydj2y73")
q = q.BottomRightFromGeoHash("drj7teegpus6")
q = q.ValidationMethod("IGNORE_MALFORMED")
q = q.IgnoreUnmapped((true))
src, err := q.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"geo_bounding_box":{"ignore_unmapped":true,"pin.location":{"bottom_right":"drj7teegpus6","top_left":"dr5r9ydj2y73"},"validation_method":"IGNORE_MALFORMED"}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}