6
6
7
7
use Meilisearch \Contracts \DocumentsQuery ;
8
8
use Meilisearch \Contracts \DocumentsResults ;
9
+ use MeiliSearch \Contracts \Task ;
9
10
use Meilisearch \Exceptions \ApiException ;
10
11
use Meilisearch \Exceptions \InvalidResponseBodyException ;
11
12
@@ -36,26 +37,29 @@ public function getDocuments(?DocumentsQuery $options = null): DocumentsResults
36
37
}
37
38
}
38
39
39
- public function addDocuments (array $ documents , ?string $ primaryKey = null ): array
40
+ public function addDocuments (array $ documents , ?string $ primaryKey = null ): Task
40
41
{
41
- return $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ]);
42
+ return Task:: fromArray ( $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ]) );
42
43
}
43
44
44
- public function addDocumentsJson (string $ documents , ?string $ primaryKey = null ): array
45
+ public function addDocumentsJson (string $ documents , ?string $ primaryKey = null ): Task
45
46
{
46
- return $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/json ' );
47
+ return Task:: fromArray ( $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/json ' ) );
47
48
}
48
49
49
- public function addDocumentsCsv (string $ documents , ?string $ primaryKey = null , ?string $ delimiter = null ): array
50
+ public function addDocumentsCsv (string $ documents , ?string $ primaryKey = null , ?string $ delimiter = null ): Task
50
51
{
51
- return $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey , 'csvDelimiter ' => $ delimiter ], 'text/csv ' );
52
+ return Task:: fromArray ( $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey , 'csvDelimiter ' => $ delimiter ], 'text/csv ' ) );
52
53
}
53
54
54
- public function addDocumentsNdjson (string $ documents , ?string $ primaryKey = null ): array
55
+ public function addDocumentsNdjson (string $ documents , ?string $ primaryKey = null ): Task
55
56
{
56
- return $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/x-ndjson ' );
57
+ return Task:: fromArray ( $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/x-ndjson ' ) );
57
58
}
58
59
60
+ /**
61
+ * @return list<Task>
62
+ */
59
63
public function addDocumentsInBatches (array $ documents , ?int $ batchSize = 1000 , ?string $ primaryKey = null ): array
60
64
{
61
65
$ promises = [];
@@ -67,6 +71,9 @@ public function addDocumentsInBatches(array $documents, ?int $batchSize = 1000,
67
71
return $ promises ;
68
72
}
69
73
74
+ /**
75
+ * @return list<Task>
76
+ */
70
77
public function addDocumentsCsvInBatches (string $ documents , ?int $ batchSize = 1000 , ?string $ primaryKey = null , ?string $ delimiter = null ): array
71
78
{
72
79
$ promises = [];
@@ -78,6 +85,9 @@ public function addDocumentsCsvInBatches(string $documents, ?int $batchSize = 10
78
85
return $ promises ;
79
86
}
80
87
88
+ /**
89
+ * @return list<Task>
90
+ */
81
91
public function addDocumentsNdjsonInBatches (string $ documents , ?int $ batchSize = 1000 , ?string $ primaryKey = null ): array
82
92
{
83
93
$ promises = [];
@@ -89,26 +99,29 @@ public function addDocumentsNdjsonInBatches(string $documents, ?int $batchSize =
89
99
return $ promises ;
90
100
}
91
101
92
- public function updateDocuments (array $ documents , ?string $ primaryKey = null ): array
102
+ public function updateDocuments (array $ documents , ?string $ primaryKey = null ): Task
93
103
{
94
- return $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ]);
104
+ return Task:: fromArray ( $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ]) );
95
105
}
96
106
97
- public function updateDocumentsJson (string $ documents , ?string $ primaryKey = null ): array
107
+ public function updateDocumentsJson (string $ documents , ?string $ primaryKey = null ): Task
98
108
{
99
- return $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/json ' );
109
+ return Task:: fromArray ( $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/json ' ) );
100
110
}
101
111
102
- public function updateDocumentsCsv (string $ documents , ?string $ primaryKey = null , ?string $ delimiter = null ): array
112
+ public function updateDocumentsCsv (string $ documents , ?string $ primaryKey = null , ?string $ delimiter = null ): Task
103
113
{
104
- return $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey , 'csvDelimiter ' => $ delimiter ], 'text/csv ' );
114
+ return Task:: fromArray ( $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey , 'csvDelimiter ' => $ delimiter ], 'text/csv ' ) );
105
115
}
106
116
107
- public function updateDocumentsNdjson (string $ documents , ?string $ primaryKey = null ): array
117
+ public function updateDocumentsNdjson (string $ documents , ?string $ primaryKey = null ): Task
108
118
{
109
- return $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/x-ndjson ' );
119
+ return Task:: fromArray ( $ this ->http ->put (self ::PATH .'/ ' .$ this ->uid .'/documents ' , $ documents , ['primaryKey ' => $ primaryKey ], 'application/x-ndjson ' ) );
110
120
}
111
121
122
+ /**
123
+ * @return list<Task>
124
+ */
112
125
public function updateDocumentsInBatches (array $ documents , ?int $ batchSize = 1000 , ?string $ primaryKey = null ): array
113
126
{
114
127
$ promises = [];
@@ -120,6 +133,9 @@ public function updateDocumentsInBatches(array $documents, ?int $batchSize = 100
120
133
return $ promises ;
121
134
}
122
135
136
+ /**
137
+ * @return list<Task>
138
+ */
123
139
public function updateDocumentsCsvInBatches (string $ documents , ?int $ batchSize = 1000 , ?string $ primaryKey = null , ?string $ delimiter = null ): array
124
140
{
125
141
$ promises = [];
@@ -131,6 +147,9 @@ public function updateDocumentsCsvInBatches(string $documents, ?int $batchSize =
131
147
return $ promises ;
132
148
}
133
149
150
+ /**
151
+ * @return list<Task>
152
+ */
134
153
public function updateDocumentsNdjsonInBatches (string $ documents , ?int $ batchSize = 1000 , ?string $ primaryKey = null ): array
135
154
{
136
155
$ promises = [];
@@ -152,31 +171,31 @@ public function updateDocumentsNdjsonInBatches(string $documents, ?int $batchSiz
152
171
* @param non-empty-string $function
153
172
* @param array{filter?: non-empty-string|list<non-empty-string>|null, context?: array<non-empty-string, mixed>} $options
154
173
*/
155
- public function updateDocumentsByFunction (string $ function , array $ options = []): array
174
+ public function updateDocumentsByFunction (string $ function , array $ options = []): Task
156
175
{
157
- return $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents/edit ' , array_merge (['function ' => $ function ], $ options ));
176
+ return Task:: fromArray ( $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents/edit ' , array_merge (['function ' => $ function ], $ options) ));
158
177
}
159
178
160
- public function deleteAllDocuments (): array
179
+ public function deleteAllDocuments (): Task
161
180
{
162
- return $ this ->http ->delete (self ::PATH .'/ ' .$ this ->uid .'/documents ' );
181
+ return Task:: fromArray ( $ this ->http ->delete (self ::PATH .'/ ' .$ this ->uid .'/documents ' ) );
163
182
}
164
183
165
- public function deleteDocument (string |int $ documentId ): array
184
+ public function deleteDocument (string |int $ documentId ): Task
166
185
{
167
- return $ this ->http ->delete (self ::PATH .'/ ' .$ this ->uid .'/documents/ ' .$ documentId );
186
+ return Task:: fromArray ( $ this ->http ->delete (self ::PATH .'/ ' .$ this ->uid .'/documents/ ' .$ documentId) );
168
187
}
169
188
170
- public function deleteDocuments (array $ options ): array
189
+ public function deleteDocuments (array $ options ): Task
171
190
{
172
191
try {
173
192
if (\array_key_exists ('filter ' , $ options ) && $ options ['filter ' ]) {
174
- return $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents/delete ' , $ options );
193
+ return Task:: fromArray ( $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents/delete ' , $ options) );
175
194
}
176
195
177
196
// backwards compatibility:
178
197
// expect to be a array to send alongside as $documents_ids.
179
- return $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents/delete-batch ' , $ options );
198
+ return Task:: fromArray ( $ this ->http ->post (self ::PATH .'/ ' .$ this ->uid .'/documents/delete-batch ' , $ options) );
180
199
} catch (InvalidResponseBodyException $ e ) {
181
200
throw ApiException::rethrowWithHint ($ e , __FUNCTION__ );
182
201
}
0 commit comments