From 5a99eb3782a2a64800ef5d63036df16d84d0a212 Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Fri, 28 Jul 2023 11:12:57 +0800 Subject: [PATCH] Support range search (#519) Signed-off-by: lixinguo Co-authored-by: lixinguo --- entity/index.go | 10 ++++++++++ entity/index_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/entity/index.go b/entity/index.go index 8de0c9b2..b6560723 100644 --- a/entity/index.go +++ b/entity/index.go @@ -67,6 +67,8 @@ type Index interface { type SearchParam interface { // returns parameters for search/query Params() map[string]interface{} + AddRadius(radius float64) + AddRangeFilter(rangeFilter float64) } type baseSearchParams struct { @@ -81,6 +83,14 @@ func (sp *baseSearchParams) Params() map[string]interface{} { return params } +func (sp *baseSearchParams) AddRadius(radius float64) { + sp.params["radius"] = radius +} + +func (sp *baseSearchParams) AddRangeFilter(rangeFilter float64) { + sp.params["range_filter"] = rangeFilter +} + func newBaseSearchParams() baseSearchParams { return baseSearchParams{ params: make(map[string]interface{}), diff --git a/entity/index_test.go b/entity/index_test.go index 4ab87b2e..ba1c7766 100644 --- a/entity/index_test.go +++ b/entity/index_test.go @@ -29,3 +29,15 @@ func TestGenericIndex(t *testing.T) { assert.Equal(t, name, gi.Name()) assert.EqualValues(t, IvfFlat, gi.Params()[tIndexType]) } + +func TestAddRadius(t *testing.T) { + params := newBaseSearchParams() + params.AddRadius(10) + assert.Equal(t, params.Params()["radius"], float64(10)) +} + +func TestAddRangeFilter(t *testing.T) { + params := newBaseSearchParams() + params.AddRangeFilter(20) + assert.Equal(t, params.Params()["range_filter"], float64(20)) +}