mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 22:46:09 -05:00
test(search): cover the cell filter parsing and the OpenSearch cell query
This commit is contained in:
1 parent
ac41685a58
commit
9c34cea0d3
3 files changed
+65
No files matched your search
@@ -35,6 +35,15 @@ var _ = Describe("ParseFilter", func() {
|
||||
Expect(got.Ranges.Numeric).To(HaveLen(2))
|
||||
})
|
||||
|
||||
It("reads the keys on a geopoint as geohash cells", func() {
|
||||
got, err := parse(&searchsvc.AggregationFilter{Field: "location", Terms: []string{"u4p", "u33dc"}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(got.Terms).To(BeEmpty())
|
||||
Expect(got.Cells).To(HaveLen(2))
|
||||
Expect(got.Cells[0].Geohash).To(Equal("u4p"))
|
||||
Expect(got.Cells[1].Geohash).To(Equal("u33dc"))
|
||||
})
|
||||
|
||||
DescribeTable("rejects what no aggregation on the field could have answered",
|
||||
func(f *searchsvc.AggregationFilter) {
|
||||
_, err := parse(f)
|
||||
@@ -51,6 +60,8 @@ var _ = Describe("ParseFilter", func() {
|
||||
Entry("another spelling of a bool", &searchsvc.AggregationFilter{Field: "audio.hasDrm", Terms: []string{"1"}}),
|
||||
Entry("a key on a date field", &searchsvc.AggregationFilter{Field: "photo.takenDateTime", Terms: []string{"2018-08-11T00:00:00Z"}}),
|
||||
Entry("a key on full text", &searchsvc.AggregationFilter{Field: "Content", Terms: []string{"fox"}}),
|
||||
Entry("a key that is no geohash on a geopoint", &searchsvc.AggregationFilter{Field: "location", Terms: []string{"u4pru", "a"}}),
|
||||
Entry("a numeric range on a geopoint", &searchsvc.AggregationFilter{Field: "location", Ranges: []*searchsvc.BucketRange{{From: "1"}}}),
|
||||
Entry("a numeric range on a keyword", &searchsvc.AggregationFilter{Field: "audio.artist", Ranges: []*searchsvc.BucketRange{{From: "1980"}}}),
|
||||
Entry("a date range on a number", &searchsvc.AggregationFilter{Field: "audio.year", Ranges: []*searchsvc.BucketRange{{From: "2018-08-11T00:00:00Z"}}}),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package osu_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestOsu(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "OpenSearch Query Builder Suite")
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package osu_test
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/opencloud-eu/opencloud/services/search/pkg/opensearch/internal/osu"
|
||||
)
|
||||
|
||||
var _ = Describe("GeoCellQuery", func() {
|
||||
halfLatStep := 180 / math.Exp2(33)
|
||||
halfLonStep := 360 / math.Exp2(33)
|
||||
|
||||
box := func(top, bottom, left, right float64) map[string]any {
|
||||
return map[string]any{"geo_bounding_box": map[string]any{"location_geopoint": map[string]any{
|
||||
"top_left": map[string]any{"lat": top, "lon": left},
|
||||
"bottom_right": map[string]any{"lat": bottom, "lon": right},
|
||||
}}}
|
||||
}
|
||||
|
||||
It("pulls the north and east edges of a cell in by half a step", func() {
|
||||
q := osu.NewGeoCellQuery("location_geopoint", 57.6123046875, 57.65625, 10.37109375, 10.4150390625)
|
||||
|
||||
Expect(q.Map()).To(Equal(box(57.65625-halfLatStep, 57.6123046875, 10.37109375, 10.4150390625-halfLonStep)))
|
||||
})
|
||||
|
||||
It("keeps the edges of the last cell at 90 and 180", func() {
|
||||
q := osu.NewGeoCellQuery("location_geopoint", 45, 90, 135, 180)
|
||||
|
||||
Expect(q.Map()).To(Equal(box(90, 45, 135, 180)))
|
||||
})
|
||||
|
||||
It("marshals to the same query", func() {
|
||||
q := osu.NewGeoCellQuery("location_geopoint", 45, 90, 135, 180)
|
||||
|
||||
Expect(q.MarshalJSON()).To(MatchJSON(`{"geo_bounding_box": {"location_geopoint": {
|
||||
"top_left": {"lat": 90, "lon": 135}, "bottom_right": {"lat": 45, "lon": 180}}}}`))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user