@@ -139,6 +139,76 @@ TEST_F(MilvusServerTestSearch, SearchWithoutIndex) {
139
139
dropCollection ();
140
140
}
141
141
142
+ TEST_F (MilvusServerTestSearch, RangeSearch) {
143
+ std::vector<milvus::FieldDataPtr> fields{
144
+ std::make_shared<milvus::Int16FieldData>(" age" , std::vector<int16_t >{12 , 13 , 14 , 15 , 16 , 17 , 18 }),
145
+ std::make_shared<milvus::VarCharFieldData>(
146
+ " name" , std::vector<std::string>{" Tom" , " Jerry" , " Lily" , " Foo" , " Bar" , " Jake" , " Jonathon" }),
147
+ std::make_shared<milvus::FloatVecFieldData>(" face" , std::vector<std::vector<float >>{
148
+ std::vector<float >{0 .1f , 0 .2f , 0 .3f , 0 .4f },
149
+ std::vector<float >{0 .2f , 0 .3f , 0 .4f , 0 .5f },
150
+ std::vector<float >{0 .3f , 0 .4f , 0 .5f , 0 .6f },
151
+ std::vector<float >{0 .4f , 0 .5f , 0 .6f , 0 .7f },
152
+ std::vector<float >{0 .5f , 0 .6f , 0 .7f , 0 .8f },
153
+ std::vector<float >{0 .6f , 0 .7f , 0 .8f , 0 .9f },
154
+ std::vector<float >{0 .7f , 0 .8f , 0 .9f , 1 .0f },
155
+ })};
156
+
157
+ createCollectionAndPartitions (true );
158
+ auto dml_results = insertRecords (fields);
159
+ loadCollection ();
160
+
161
+ milvus::SearchArguments arguments{};
162
+ arguments.SetCollectionName (collection_name);
163
+ arguments.AddPartitionName (partition_name);
164
+ arguments.SetRange (0.3 , 1.0 );
165
+ arguments.SetTopK (10 );
166
+ arguments.AddOutputField (" age" );
167
+ arguments.AddOutputField (" name" );
168
+ arguments.AddTargetVector (" face" , std::vector<float >{0 .f , 0 .f , 0 .f , 0 .f });
169
+ arguments.AddTargetVector (" face" , std::vector<float >{1 .f , 1 .f , 1 .f , 1 .f });
170
+ milvus::SearchResults search_results{};
171
+ auto status = client_->Search (arguments, search_results);
172
+ EXPECT_EQ (status.Message (), " OK" );
173
+ EXPECT_TRUE (status.IsOk ());
174
+
175
+ const auto & results = search_results.Results ();
176
+ EXPECT_EQ (results.size (), 2 );
177
+
178
+ // validate results
179
+ auto validateScores = [&results](int firstRet, int secondRet) {
180
+ // check score should between range
181
+ for (const auto & result : results) {
182
+ for (const auto & score : result.Scores ()) {
183
+ EXPECT_GE (score, 0.3 );
184
+ EXPECT_LE (score, 1.0 );
185
+ }
186
+ }
187
+ EXPECT_EQ (results.at (0 ).Ids ().IntIDArray ().size (), firstRet);
188
+ EXPECT_EQ (results.at (1 ).Ids ().IntIDArray ().size (), secondRet);
189
+ };
190
+
191
+ // valid score in range is 3, 2
192
+ validateScores (3 , 2 );
193
+
194
+ // add fields, then search again, should be 6 and 4
195
+ insertRecords (fields);
196
+ loadCollection ();
197
+ status = client_->Search (arguments, search_results);
198
+ EXPECT_TRUE (status.IsOk ());
199
+ validateScores (6 , 4 );
200
+
201
+ // add fields twice, and now it should be 12, 8, as limit is 10, then should be 10, 8
202
+ insertRecords (fields);
203
+ insertRecords (fields);
204
+ loadCollection ();
205
+ status = client_->Search (arguments, search_results);
206
+ EXPECT_TRUE (status.IsOk ());
207
+ validateScores (10 , 8 );
208
+
209
+ dropCollection ();
210
+ }
211
+
142
212
TEST_F (MilvusServerTestSearch, SearchWithStringFilter) {
143
213
std::vector<milvus::FieldDataPtr> fields{
144
214
std::make_shared<milvus::Int16FieldData>(" age" , std::vector<int16_t >{12 , 13 }),
0 commit comments