diff --git a/services/graph/pkg/service/v0/searchquery_mapping.go b/services/graph/pkg/service/v0/searchquery_mapping.go index 719e503e3e..5ad25fe1e9 100644 --- a/services/graph/pkg/service/v0/searchquery_mapping.go +++ b/services/graph/pkg/service/v0/searchquery_mapping.go @@ -151,12 +151,15 @@ func searchAggregationsToLibregraph(in []*searchsvc.AggregationResult, defs []li ranges := libregraphRangesToSearch(def.BucketDefinition.GetRanges()) agg.Buckets = make([]libregraph.SearchBucket, 0, len(in[i].GetBuckets())) for _, b := range in[i].GetBuckets() { - agg.Buckets = append(agg.Buckets, libregraph.SearchBucket{ + bucket := libregraph.SearchBucket{ Key: libregraph.PtrString(b.GetKey()), Count: libregraph.PtrInt64(b.GetCount()), - AggregationFilterToken: libregraph.PtrString(aggregationFilterToken(b.GetKey(), ranges)), LibreGraphSubAggregations: searchAggregationsToLibregraph(b.GetSubAggregations(), def.LibreGraphSubAggregations), - }) + } + if def.LibreGraphGeohashDefinition == nil { + bucket.AggregationFilterToken = libregraph.PtrString(aggregationFilterToken(b.GetKey(), ranges)) + } + agg.Buckets = append(agg.Buckets, bucket) } out = append(out, agg) } diff --git a/services/graph/pkg/service/v0/searchquery_test.go b/services/graph/pkg/service/v0/searchquery_test.go index f50197e765..a807f794b4 100644 --- a/services/graph/pkg/service/v0/searchquery_test.go +++ b/services/graph/pkg/service/v0/searchquery_test.go @@ -468,6 +468,24 @@ var _ = ginkgo.Describe("SearchQuery", func() { Expect(captured().GetAggregations()[0].GetGeohashDefinition().GetPrecision()).To(Equal(int32(5))) }) + ginkgo.It("answers geohash cells without a filter token, their sub-aggregations with one", func() { + g, _ := graphWithAggregations(&searchsvc.AggregationResult{ + Field: "location", + Buckets: []*searchsvc.Bucket{{Key: "u4pru", Count: 2, SubAggregations: []*searchsvc.AggregationResult{ + {Field: "MimeType", Buckets: []*searchsvc.Bucket{{Key: "image/jpeg", Count: 2}}}, + }}}, + }) + rr := postSearchQuery(g, searchQueryBody(`"aggregations": [{"field": "location", "@libre.graph.geohashDefinition": {"precision": 5}, + "@libre.graph.subAggregations": [{"field": "mimeType"}]}]`)) + Expect(rr.Code).To(Equal(http.StatusOK), rr.Body.String()) + + cell := hitsContainer(rr).Aggregations[0].Buckets[0] + Expect(cell.Key).To(Equal("u4pru")) + Expect(cell.Token).To(BeEmpty()) + Expect(rr.Body.String()).ToNot(ContainSubstring("ǂǂ7534707275")) + Expect(cell.SubAggregations[0].Buckets[0].Token).To(Equal(`"ǂǂ696d6167652f6a706567"`)) + }) + ginkgo.It("rejects an $expand it does not know with 400", func() { req := httptest.NewRequest(http.MethodPost, "/search/query?$expand=thumbnails,permissions", bytes.NewBufferString(searchQueryBody(`"from": 0`))) rr := httptest.NewRecorder()