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+ 'wait ' => 'true '
40+ ]
41+ );
42+
43+ $ this ->assertEquals ('ok ' , $ response ['status ' ]);
44+ $ this ->assertEquals ('completed ' , $ response ['result ' ]['status ' ]);
45+
46+ $ response = $ this ->getCollections ('sample-collection ' )->points ()
47+ ->upsert (
48+ PointsStruct::createFromArray (self ::basicPointDataProvider ()[0 ][0 ]),
49+ [
50+ 'wait ' => 'true '
51+ ]
52+ );
53+
54+ $ this ->assertEquals ('ok ' , $ response ['status ' ]);
55+ $ this ->assertEquals ('completed ' , $ response ['result ' ]['status ' ]);
56+ }
57+
58+ public static function basicPointDataProvider (): array
59+ {
60+ return [
61+ [
62+ [
63+ [
64+ 'id ' => 1 ,
65+ 'vector ' => new VectorStruct ([1 , 3 , 400 ], 'image ' ),
66+ 'payload ' => [
67+ 'sort ' => 1 ,
68+ 'color ' => 'red '
69+ ]
70+ ],
71+ [
72+ 'id ' => 2 ,
73+ 'vector ' => new VectorStruct ([1 , 3 , 300 ], 'image ' ),
74+ 'payload ' => [
75+ 'sort ' => 2 ,
76+ 'color ' => 'red '
77+ ]
78+ ],
79+ [
80+ 'id ' => 3 ,
81+ 'vector ' => new VectorStruct ([1 , 3 , 300 ], 'image ' ),
82+ 'payload ' => [
83+ 'sort ' => 3 ,
84+ 'color ' => 'green '
85+ ]
86+ ],
87+ ]
88+ ]
89+ ];
90+ }
91+
92+ public function testScrollAscPoint (): void
93+ {
94+ $ filter = (new Filter ())->addMust (
95+ new MatchString ('color ' , 'red ' )
96+ );
97+
98+ $ scroll = (new ScrollRequest ())->setFilter ($ filter )->setOrderBy ('sort ' );
99+ $ response = $ this ->getCollections ('sample-collection ' )->points ()->scroll ($ scroll );
100+
101+ $ this ->assertEquals ('ok ' , $ response ['status ' ]);
102+ $ this ->assertCount (2 , $ response ['result ' ]);
103+ $ this ->assertEquals (1 , $ response ['result ' ]['points ' ][0 ]['id ' ]);
104+ }
105+
106+ public function testScrollDescPoint (): void
107+ {
108+ $ filter = (new Filter ())->addMust (
109+ new MatchString ('color ' , 'red ' )
110+ );
111+
112+ $ scroll = (new ScrollRequest ())->setFilter ($ filter )->setOrderBy ([
113+ 'key ' => 'sort ' ,
114+ 'direction ' => 'desc '
115+ ]);
116+ $ response = $ this ->getCollections ('sample-collection ' )->points ()->scroll ($ scroll );
117+
118+ $ this ->assertEquals ('ok ' , $ response ['status ' ]);
119+ $ this ->assertCount (2 , $ response ['result ' ]);
120+ $ this ->assertEquals (2 , $ response ['result ' ]['points ' ][0 ]['id ' ]);
121+ }
122+
123+ protected function tearDown (): void
124+ {
125+ parent ::tearDown ();
126+ $ collections = new Collections ($ this ->client );
127+
128+ $ collections ->setCollectionName ('sample-collection ' )->delete ();
129+ }
130+ }
0 commit comments