@@ -52,7 +52,7 @@ static HttpResponse errInvalidParameter(const QString &description) {
52
52
return errBadRequest (" invalid_parameter" , description);
53
53
}
54
54
55
- static HttpResponse errInvalidTerms () { return errBadRequest (" invalid_terms " , " invalid terms " ); }
55
+ static HttpResponse errInvalidTerms () { return errBadRequest (" invalid_hashes " , " invalid hashes " ); }
56
56
57
57
static QString getIndexName (const HttpRequest &request) {
58
58
auto indexName = request.param (" :index" );
@@ -170,7 +170,7 @@ static HttpResponse handlePutDocumentRequest(const HttpRequest &request, const Q
170
170
if (body.isEmpty ()) {
171
171
return errInvalidTerms ();
172
172
}
173
- auto terms = parseTerms (body.value (" terms " ));
173
+ auto terms = parseTerms (body.value (" hashes " ));
174
174
175
175
try {
176
176
auto writer = index ->openWriter (true , 1000 );
@@ -222,48 +222,48 @@ static HttpResponse handleSearchRequest(const HttpRequest &request, const QShare
222
222
return HttpResponse (HTTP_OK, QJsonDocument (responseJson));
223
223
}
224
224
225
- // Handle bulk requests.
226
- static HttpResponse handleBulkRequest (const HttpRequest &request, const QSharedPointer<Index> &indexes) {
225
+ // Handle bulk update requests.
226
+ static HttpResponse handleUpdateRequest (const HttpRequest &request, const QSharedPointer<Index> &indexes) {
227
227
auto index = getIndex (request, indexes);
228
228
229
229
QJsonArray opsJsonArray;
230
230
231
231
auto doc = request.json ();
232
232
if (doc.isObject ()) {
233
233
auto obj = doc.object ();
234
- if (obj.contains (" operations " )) {
235
- auto value = obj.value (" operations " );
234
+ if (obj.contains (" changes " )) {
235
+ auto value = obj.value (" changes " );
236
236
if (value.isArray ()) {
237
237
opsJsonArray = value.toArray ();
238
238
} else {
239
- return errBadRequest (" invalid_bulk_operation " , " 'operations ' must be an array" );
239
+ return errBadRequest (" invalid_bulk_update " , " 'changes ' must be an array" );
240
240
}
241
241
}
242
242
} else if (doc.isArray ()) {
243
243
opsJsonArray = doc.array ();
244
244
} else {
245
- return errBadRequest (" invalid_bulk_operation " ,
246
- " request body must be either an array or an object with 'operations ' key in it" );
245
+ return errBadRequest (" invalid_bulk_update " ,
246
+ " request body must be either an array or an object with 'changes ' key in it" );
247
247
}
248
248
249
249
try {
250
250
auto writer = index ->openWriter (true , 1000 );
251
- for (auto operation : opsJsonArray) {
252
- if (!operation .isObject ()) {
253
- return errBadRequest (" invalid_bulk_operation " , " operation must be an object" );
251
+ for (auto change : opsJsonArray) {
252
+ if (!change .isObject ()) {
253
+ return errBadRequest (" invalid_bulk_update " , " change must be an object" );
254
254
}
255
- auto operationObj = operation .toObject ();
256
- if (operationObj .contains (" upsert " )) {
257
- auto docObj = operationObj .value (" upsert " ).toObject ();
255
+ auto changeObj = change .toObject ();
256
+ if (changeObj .contains (" insert " )) {
257
+ auto docObj = changeObj .value (" insert " ).toObject ();
258
258
auto docId = docObj.value (" id" ).toInt ();
259
- auto terms = parseTerms (docObj.value (" terms " ));
259
+ auto terms = parseTerms (docObj.value (" hashes " ));
260
260
writer->addDocument (docId, terms.data (), terms.size ());
261
261
}
262
- if (operationObj .contains (" delete" )) {
262
+ if (changeObj .contains (" delete" )) {
263
263
return errNotImplemented (" not implemented in this version of acoustid-index" );
264
264
}
265
- if (operationObj .contains (" set " )) {
266
- auto attrObj = operationObj .value (" set " ).toObject ();
265
+ if (changeObj .contains (" set_attribute " )) {
266
+ auto attrObj = changeObj .value (" set_attribute " ).toObject ();
267
267
auto name = attrObj.value (" name" ).toString ();
268
268
auto value = attrObj.value (" value" ).toString ();
269
269
writer->setAttribute (name, value);
@@ -294,22 +294,22 @@ HttpRequestHandler::HttpRequestHandler(QSharedPointer<Index> indexes, QSharedPoi
294
294
});
295
295
296
296
// Document API
297
- m_router.route (HTTP_HEAD, " /:index/_doc/ :docId" , [=](auto req) {
297
+ m_router.route (HTTP_HEAD, " /:index/:docId" , [=](auto req) {
298
298
return handleHeadDocumentRequest (req, m_indexes);
299
299
});
300
- m_router.route (HTTP_GET, " /:index/_doc/ :docId" , [=](auto req) {
300
+ m_router.route (HTTP_GET, " /:index/:docId" , [=](auto req) {
301
301
return handleGetDocumentRequest (req, m_indexes);
302
302
});
303
- m_router.route (HTTP_PUT, " /:index/_doc/ :docId" , [=](auto req) {
303
+ m_router.route (HTTP_PUT, " /:index/:docId" , [=](auto req) {
304
304
return handlePutDocumentRequest (req, m_indexes);
305
305
});
306
- m_router.route (HTTP_DELETE, " /:index/_doc/ :docId" , [=](auto req) {
306
+ m_router.route (HTTP_DELETE, " /:index/:docId" , [=](auto req) {
307
307
return handleDeleteDocumentRequest (req, m_indexes);
308
308
});
309
309
310
- // Bulk API
311
- m_router.route (HTTP_POST, " /:index/_bulk " , [=](auto req) {
312
- return handleBulkRequest (req, m_indexes);
310
+ // Update API
311
+ m_router.route (HTTP_POST, " /:index/_update " , [=](auto req) {
312
+ return handleUpdateRequest (req, m_indexes);
313
313
});
314
314
315
315
// Search API
0 commit comments