From 90280de7189a46fa4c5493117498793dae06099f Mon Sep 17 00:00:00 2001 From: Patrick Weizhi Xu Date: Sat, 14 Sep 2024 15:27:04 +0800 Subject: [PATCH] feat: add page retain order for range search Signed-off-by: Patrick Weizhi Xu --- entity/index.go | 5 +++++ entity/index_test.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/entity/index.go b/entity/index.go index eafdadeb..bf5717bc 100644 --- a/entity/index.go +++ b/entity/index.go @@ -89,6 +89,7 @@ type SearchParam interface { Params() map[string]interface{} AddRadius(radius float64) AddRangeFilter(rangeFilter float64) + AddPageRetainOrder(pageRetainOrder bool) } type baseSearchParams struct { @@ -111,6 +112,10 @@ func (sp *baseSearchParams) AddRangeFilter(rangeFilter float64) { sp.params["range_filter"] = rangeFilter } +func (sp *baseSearchParams) AddPageRetainOrder(pageRetainOrder bool) { + sp.params["page_retain_order"] = pageRetainOrder +} + func newBaseSearchParams() baseSearchParams { return baseSearchParams{ params: make(map[string]interface{}), diff --git a/entity/index_test.go b/entity/index_test.go index 06188ed1..5411e5a1 100644 --- a/entity/index_test.go +++ b/entity/index_test.go @@ -41,6 +41,12 @@ func TestAddRangeFilter(t *testing.T) { assert.Equal(t, params.Params()["range_filter"], float64(20)) } +func TestPageRetainOrder(t *testing.T) { + params := newBaseSearchParams() + params.AddPageRetainOrder(true) + assert.Equal(t, params.Params()["page_retain_order"], true) +} + func TestIndexGPUCagra(t *testing.T) { t.Run("index", func(t *testing.T) { index, err := NewIndexGPUCagra(L2, 64, 64)