Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 6521d96

Browse files
committed
feat(deleteByQuery): Implement deleteBy, deprecate old method
1 parent 9fcff0a commit 6521d96

File tree

1 file changed

+37
-3
lines changed
  • algoliasearch/src/main/java/com/algolia/search/saas

1 file changed

+37
-3
lines changed

algoliasearch/src/main/java/com/algolia/search/saas/Index.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ public Request getObjectsAsync(final @NonNull List<String> objectIDs, final List
479479
* @param taskID Identifier of the task (as returned by the server).
480480
* @param completionHandler The listener that will be notified of the request's outcome.
481481
* @return A cancellable request.
482-
*
483482
* @deprecated Task IDs are always integers. Please use {@link #waitTaskAsync(int, CompletionHandler)} instead.
484483
*/
485484
public Request waitTaskAsync(final @NonNull String taskID, @NonNull CompletionHandler completionHandler) {
@@ -541,11 +540,12 @@ public Request deleteObjectsAsync(final @NonNull List<String> objectIDs, Complet
541540
}
542541

543542
/**
544-
* Delete all objects matching a query (helper).
543+
* Delete all objects matching a query (helper) using browse and deleteObjects.
545544
*
546545
* @param query The query that objects to delete must match.
547546
* @param completionHandler The listener that will be notified of the request's outcome.
548547
* @return A cancellable request.
548+
* @deprecated use {@link Index#deleteByAsync(Query, CompletionHandler)} instead.
549549
*/
550550
public Request deleteByQueryAsync(@NonNull Query query, CompletionHandler completionHandler) {
551551
final Query queryCopy = new Query(query);
@@ -558,6 +558,23 @@ public Request deleteByQueryAsync(@NonNull Query query, CompletionHandler comple
558558
}.start();
559559
}
560560

561+
/**
562+
* Delete all objects matching a query (helper).
563+
*
564+
* @param query The query that objects to delete must match.
565+
* @param completionHandler The listener that will be notified of the request's outcome.
566+
* @return A cancellable request.
567+
*/
568+
public Request deleteByAsync(@NonNull Query query, CompletionHandler completionHandler) {
569+
final Query queryCopy = new Query(query);
570+
return getClient().new AsyncTaskRequest(completionHandler) {
571+
@NonNull
572+
@Override protected JSONObject run() throws AlgoliaException {
573+
return deleteBy(queryCopy);
574+
}
575+
}.start();
576+
}
577+
561578
/**
562579
* Get this index's settings (asynchronously).
563580
*
@@ -960,11 +977,13 @@ protected JSONObject deleteObjects(List<String> objects) throws AlgoliaException
960977
}
961978

962979
/**
963-
* Delete all objects matching a query
980+
* Delete all objects matching a query using browse and deleteObjects.
964981
*
965982
* @param query the query string
966983
* @throws AlgoliaException
984+
* @deprecated use {@link Index#deleteBy(Query)} instead.
967985
*/
986+
@Deprecated
968987
protected void deleteByQuery(@NonNull Query query) throws AlgoliaException {
969988
try {
970989
boolean hasMore;
@@ -990,6 +1009,21 @@ protected void deleteByQuery(@NonNull Query query) throws AlgoliaException {
9901009
}
9911010
}
9921011

1012+
/**
1013+
* Delete all records matching the query.
1014+
*
1015+
* @param query the query string
1016+
* @throws AlgoliaException
1017+
*/
1018+
protected JSONObject deleteBy(@NonNull Query query) throws AlgoliaException {
1019+
try {
1020+
return client.postRequest("/1/indexes/" + indexName + "/deleteByQuery", new JSONObject().put("params", query.build()).toString(), false);
1021+
} catch (JSONException e) {
1022+
e.printStackTrace();
1023+
return null;
1024+
}
1025+
}
1026+
9931027
/**
9941028
* Search inside the index
9951029
*

0 commit comments

Comments
 (0)