@@ -33,6 +33,11 @@ class DocumentsQuery
3333 */
3434 private ?array $ ids = null ;
3535
36+ /**
37+ * @var list<non-empty-string>|null
38+ */
39+ private ?array $ sort = null ;
40+
3641 /**
3742 * @param non-negative-int $offset
3843 *
@@ -117,46 +122,37 @@ public function hasFilter(): bool
117122 return null !== $ this ->filter ;
118123 }
119124
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+
120135 /**
121136 * @return array{
122137 * offset?: non-negative-int,
123138 * limit?: non-negative-int,
124139 * fields?: non-empty-list<string>|non-empty-string,
125140 * filter?: list<non-empty-string|list<non-empty-string>>,
126141 * retrieveVectors?: bool,
127- * ids?: string
142+ * ids?: string,
143+ * sort?: non-empty-list<string>,
128144 * }
129145 */
130146 public function toArray (): array
131147 {
132148 return array_filter ([
133149 'offset ' => $ this ->offset ,
134150 'limit ' => $ this ->limit ,
135- 'fields ' => $ this ->getFields () ,
151+ 'fields ' => $ this ->fields ,
136152 'filter ' => $ this ->filter ,
137153 'retrieveVectors ' => $ this ->retrieveVectors ,
138154 'ids ' => ($ this ->ids ?? []) !== [] ? implode (', ' , $ this ->ids ) : null ,
155+ 'sort ' => $ this ->sort ,
139156 ], static function ($ item ) { return null !== $ item ; });
140157 }
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- }
162158}
0 commit comments