Repository: milvus-io/milvus-sdk-go
Pull request #519 (2023-07-18 10:04:33)

Support range search
Signed-off-by: lixinguo [xinguo.li@zilliz.com](mailto:xinguo.li@zilliz.com)
https://github.com/milvus-io/milvus/issues/21655

sre-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/519#" title="Author self-approved">smellthemoon</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **congqixia** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @congqixia` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["congqixia"]} -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) Report
> Merging [#519](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (e8675c5) into [master](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/bfb377d964c8f3ae262b5693922363ece1ccea2d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (bfb377d) will **decrease** coverage by `0.12%`.
> The diff coverage is `85.71%`.

[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519/graphs/tree.svg?width=650&height=150&src=pr&token=WJK43PV390&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)

```diff
@@            Coverage Diff             @@
##           master     #519      +/-   ##
==========================================
- Coverage   82.75%   82.63%   -0.12%     
==========================================
  Files          39       39              
  Lines        3519     3525       +6     
==========================================
+ Hits         2912     2913       +1     
- Misses        498      504       +6     
+ Partials      109      108       -1     
```


| [Impacted Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) | Coverage Δ | |
|---|---|---|
| [client/data.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-Y2xpZW50L2RhdGEuZ28=) | `69.20% <0.00%> (-0.20%)` | :arrow_down: |
| [client/options.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-Y2xpZW50L29wdGlvbnMuZ28=) | `63.63% <100.00%> (+2.52%)` | :arrow_up: |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/519/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)

sre-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/519#" title="Author self-approved">smellthemoon</a>*, *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/519#pullrequestreview-1549423400" title="LGTM">yah01</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **congqixia** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @congqixia` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["congqixia"]} -->
congqixia: /approve
sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/519#issuecomment-1654913856" title="Approved">congqixia</a>*, *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/519#" title="Author self-approved">smellthemoon</a>*, *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/519#pullrequestreview-1549423400" title="LGTM">yah01</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/entity/index.go b/entity/index.go
index 8de0c9b..b656072 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{}),


Test patch:
diff --git a/entity/index_test.go b/entity/index_test.go
index 4ab87b2..ba1c776 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))
+}