Skip to content

Commit

Permalink
Support range search (#519)
Browse files Browse the repository at this point in the history
Signed-off-by: lixinguo <[email protected]>
Co-authored-by: lixinguo <[email protected]>
  • Loading branch information
smellthemoon and lixinguo authored Jul 28, 2023
1 parent e7ea7dd commit 5a99eb3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions entity/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{}),
Expand Down
12 changes: 12 additions & 0 deletions entity/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 5a99eb3

Please sign in to comment.