@@ -228,4 +228,49 @@ public function testStoreCanQuery()
228
228
$ this ->assertSame (1 , $ httpClient ->getRequestsCount ());
229
229
$ this ->assertCount (2 , $ results );
230
230
}
231
+
232
+ public function testStoreCanQueryWithFilters ()
233
+ {
234
+ $ httpClient = new MockHttpClient ([
235
+ new JsonMockResponse ([
236
+ 'result ' => [
237
+ 'points ' => [
238
+ [
239
+ 'id ' => Uuid::v4 ()->toRfc4122 (),
240
+ 'vector ' => [0.1 , 0.2 , 0.3 ],
241
+ 'payload ' => ['foo ' => 'bar ' ],
242
+ ],
243
+ [
244
+ 'id ' => Uuid::v4 ()->toRfc4122 (),
245
+ 'vector ' => [0.2 , 0.1 , 0.3 ],
246
+ 'payload ' => ['foo ' => ['bar ' , 'baz ' ]],
247
+ ],
248
+ ],
249
+ ],
250
+ ], [
251
+ 'http_code ' => 200 ,
252
+ ]),
253
+ ], 'http://127.0.0.1:6333 ' );
254
+
255
+ $ store = new Store ($ httpClient , 'http://127.0.0.1:6333 ' , 'test ' , 'test ' );
256
+
257
+ $ results = $ store ->query (new Vector ([0.1 , 0.2 , 0.3 ]), [
258
+ 'filter ' => [
259
+ 'must ' => [
260
+ ['key ' => 'foo ' , 'match ' => ['value ' => 'bar ' ]],
261
+ ],
262
+ ],
263
+ ]);
264
+
265
+ $ this ->assertSame (1 , $ httpClient ->getRequestsCount ());
266
+ $ this ->assertCount (2 , $ results );
267
+
268
+ foreach ($ results as $ result ) {
269
+ $ this ->assertArrayHasKey ('foo ' , $ result ->metadata );
270
+ $ this ->assertTrue (
271
+ 'bar ' === $ result ->metadata ['foo ' ] || (\is_array ($ result ->metadata ['foo ' ]) && \in_array ('bar ' , $ result ->metadata ['foo ' ], true )),
272
+ "Value should be 'bar' or an array containing 'bar' "
273
+ );
274
+ }
275
+ }
231
276
}
0 commit comments