1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Integration \Endpoints \Collections ;
8+
9+ use Qdrant \Endpoints \Collections ;
10+ use Qdrant \Exception \InvalidArgumentException ;
11+ use Qdrant \Models \Filter \Condition \MatchString ;
12+ use Qdrant \Models \Filter \Filter ;
13+ use Qdrant \Models \PointsStruct ;
14+ use Qdrant \Models \Request \CreateIndex ;
15+ use Qdrant \Models \Request \ScrollRequest ;
16+ use Qdrant \Models \Request \SearchRequest ;
17+ use Qdrant \Models \VectorStruct ;
18+ use Qdrant \Tests \Integration \AbstractIntegration ;
19+
20+ class SearchSortTest extends AbstractIntegration
21+ {
22+ /**
23+ * @throws InvalidArgumentException
24+ */
25+ public function setUp (): void
26+ {
27+ parent ::setUp ();
28+
29+ $ this ->createCollections ('sample-collection ' );
30+
31+ $ response = $ this ->getCollections ('sample-collection ' )->index ()->create (
32+ (new CreateIndex ('sort ' , [
33+ 'type ' => 'integer ' ,
34+ 'range ' => true ,
35+ 'lookup ' => false ,
36+ 'is_principal ' => true
37+ ]))
38+ );
39+
40+ $ this ->assertEquals ('ok ' , $ response ['status ' ]);
41+ $ this ->assertEquals ('acknowledged ' , $ response ['result ' ]['status ' ]);
42+
43+ $ response = $ this ->getCollections ('sample-collection ' )->points ()
44+ ->upsert (PointsStruct::createFromArray (self ::basicPointDataProvider ()[0 ][0 ]));
45+
46+ $ this ->assertEquals ('ok ' , $ response ['status ' ]);
47+ $ this ->assertEquals ('acknowledged ' , $ response ['result ' ]['status ' ]);
48+ }
49+
50+ public static function basicPointDataProvider (): array
51+ {
52+ return [
53+ [
54+ [
55+ [
56+ 'id ' => 1 ,
57+ 'vector ' => new VectorStruct ([1 , 3 , 400 ], 'image ' ),
58+ 'payload ' => [
59+ 'sort ' => 1 ,
60+ 'color ' => 'red '
61+ ]
62+ ],
63+ [
64+ 'id ' => 2 ,
65+ 'vector ' => new VectorStruct ([1 , 3 , 300 ], 'image ' ),
66+ 'payload ' => [
67+ 'sort ' => 2 ,
68+ 'image ' => 'red '
69+ ]
70+ ],
71+ [
72+ 'id ' => 3 ,
73+ 'vector ' => new VectorStruct ([1 , 3 , 300 ], 'image ' ),
74+ 'payload ' => [
75+ 'sort ' => 3 ,
76+ 'image ' => 'green '
77+ ]
78+ ],
79+ ]
80+ ]
81+ ];
82+ }
83+
84+ public function testSearchPoint (): void
85+ {
86+ $ filter = (new Filter ())->addMust (
87+ new MatchString ('color ' , 'red ' )
88+ );
89+
90+ $ scroll = (new ScrollRequest ())->setFilter ($ filter )->setOrderBy ('sort ' );
91+ $ response = $ this ->getCollections ('sample-collection ' )->points ()->scroll ($ scroll );
92+
93+ $ this ->assertEquals ('ok ' , $ response ['status ' ]);
94+ $ this ->assertCount (2 , $ response ['result ' ]);
95+ }
96+
97+
98+ protected function tearDown (): void
99+ {
100+ parent ::tearDown ();
101+ $ collections = new Collections ($ this ->client );
102+
103+ $ collections ->setCollectionName ('sample-collection ' )->delete ();
104+ }
105+ }
0 commit comments