@@ -33,6 +33,11 @@ class DocumentsQuery
33
33
*/
34
34
private ?array $ ids = null ;
35
35
36
+ /**
37
+ * @var list<non-empty-string>|null
38
+ */
39
+ private ?array $ sort = null ;
40
+
36
41
/**
37
42
* @param non-negative-int $offset
38
43
*
@@ -117,46 +122,37 @@ public function hasFilter(): bool
117
122
return null !== $ this ->filter ;
118
123
}
119
124
125
+ /**
126
+ * @param list<non-empty-string> $sort
127
+ */
128
+ public function setSort (array $ sort ): self
129
+ {
130
+ $ this ->sort = $ sort ;
131
+
132
+ return $ this ;
133
+ }
134
+
120
135
/**
121
136
* @return array{
122
137
* offset?: non-negative-int,
123
138
* limit?: non-negative-int,
124
139
* fields?: non-empty-list<string>|non-empty-string,
125
140
* filter?: list<non-empty-string|list<non-empty-string>>,
126
141
* retrieveVectors?: bool,
127
- * ids?: string
142
+ * ids?: string,
143
+ * sort?: non-empty-list<string>,
128
144
* }
129
145
*/
130
146
public function toArray (): array
131
147
{
132
148
return array_filter ([
133
149
'offset ' => $ this ->offset ,
134
150
'limit ' => $ this ->limit ,
135
- 'fields ' => $ this ->getFields () ,
151
+ 'fields ' => $ this ->fields ,
136
152
'filter ' => $ this ->filter ,
137
153
'retrieveVectors ' => $ this ->retrieveVectors ,
138
154
'ids ' => ($ this ->ids ?? []) !== [] ? implode (', ' , $ this ->ids ) : null ,
155
+ 'sort ' => $ this ->sort ,
139
156
], static function ($ item ) { return null !== $ item ; });
140
157
}
141
-
142
- /**
143
- * Prepares fields for request
144
- * Fix for 1.2 document/fetch.
145
- *
146
- * @see https://github.com/meilisearch/meilisearch-php/issues/522
147
- *
148
- * @return array|string|null
149
- */
150
- private function getFields ()
151
- {
152
- if (null === $ this ->fields ) {
153
- return null ;
154
- }
155
-
156
- if (null !== $ this ->filter ) {
157
- return $ this ->fields ;
158
- }
159
-
160
- return implode (', ' , $ this ->fields );
161
- }
162
158
}
0 commit comments