Skip to content

Commit

Permalink
Merge pull request #510 from meilisearch/tasks_changes
Browse files Browse the repository at this point in the history
Apply tasks changes
  • Loading branch information
alallema authored Dec 27, 2022
2 parents 560ebd8 + 67556ac commit 9abd107
Show file tree
Hide file tree
Showing 18 changed files with 578 additions and 397 deletions.
32 changes: 23 additions & 9 deletions src/main/java/com/meilisearch/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import com.meilisearch.sdk.model.Results;
import com.meilisearch.sdk.model.Stats;
import com.meilisearch.sdk.model.Task;
import com.meilisearch.sdk.model.TaskInfo;
import com.meilisearch.sdk.model.TasksQuery;
import com.meilisearch.sdk.model.TasksResults;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
Expand Down Expand Up @@ -43,10 +46,10 @@ public Client(Config config) {
* https://docs.meilisearch.com/reference/api/indexes.html#create-an-index
*
* @param uid Unique identifier for the index to create
* @return Meilisearch API response as Task
* @return Meilisearch API response as TaskInfo
* @throws MeilisearchException if an error occurs
*/
public Task createIndex(String uid) throws MeilisearchException {
public TaskInfo createIndex(String uid) throws MeilisearchException {
return this.createIndex(uid, null);
}

Expand All @@ -56,10 +59,10 @@ public Task createIndex(String uid) throws MeilisearchException {
*
* @param uid Unique identifier for the index to create
* @param primaryKey The primary key of the documents in that index
* @return Meilisearch API response as Task
* @return Meilisearch API response as TaskInfo
* @throws MeilisearchException if an error occurs
*/
public Task createIndex(String uid, String primaryKey) throws MeilisearchException {
public TaskInfo createIndex(String uid, String primaryKey) throws MeilisearchException {
return this.indexesHandler.create(uid, primaryKey);
}

Expand Down Expand Up @@ -137,10 +140,10 @@ public String getRawIndex(String uid) throws MeilisearchException {
*
* @param uid Unique identifier of the index to update
* @param primaryKey Primary key of the documents in the index
* @return Meilisearch API response as Task
* @return Meilisearch API response as TaskInfo
* @throws MeilisearchException if an error occurs
*/
public Task updateIndex(String uid, String primaryKey) throws MeilisearchException {
public TaskInfo updateIndex(String uid, String primaryKey) throws MeilisearchException {
return this.indexesHandler.updatePrimaryKey(uid, primaryKey);
}

Expand All @@ -149,10 +152,10 @@ public Task updateIndex(String uid, String primaryKey) throws MeilisearchExcepti
* https://docs.meilisearch.com/reference/api/indexes.html#delete-one-index
*
* @param uid Unique identifier of the index to delete
* @return Meilisearch API response as Task
* @return Meilisearch API response as TaskInfo
* @throws MeilisearchException if an error occurs
*/
public Task deleteIndex(String uid) throws MeilisearchException {
public TaskInfo deleteIndex(String uid) throws MeilisearchException {
return this.indexesHandler.delete(uid);
}

Expand Down Expand Up @@ -240,10 +243,21 @@ public Task getTask(int uid) throws MeilisearchException {
* @return List of tasks in the Meilisearch client
* @throws MeilisearchException if an error occurs
*/
public Results<Task> getTasks() throws MeilisearchException {
public TasksResults getTasks() throws MeilisearchException {
return this.tasksHandler.getTasks();
}

/**
* Retrieves list of tasks https://docs.meilisearch.com/reference/api/tasks.html#get-tasks
*
* @param param accept by the tasks route
* @return List of tasks in the Meilisearch client
* @throws MeilisearchException if an error occurs
*/
public TasksResults getTasks(TasksQuery param) throws MeilisearchException {
return this.tasksHandler.getTasks(param);
}

/**
* Waits for a task to be processed
*
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/com/meilisearch/sdk/Documents.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.util.Collections.singletonList;

import com.meilisearch.sdk.exceptions.MeilisearchException;
import com.meilisearch.sdk.model.Task;
import com.meilisearch.sdk.model.TaskInfo;
import java.util.List;

/**
Expand Down Expand Up @@ -106,15 +106,16 @@ String getDocuments(String uid, int limit, int offset, List<String> attributesTo
* @param uid Partial index identifier for the document
* @param document String containing the document to add
* @param primaryKey PrimaryKey of the document
* @return Meilisearch's Task API response
* @return Meilisearch's TaskInfo API response
* @throws MeilisearchException if the client request causes an error
*/
Task addDocuments(String uid, String document, String primaryKey) throws MeilisearchException {
TaskInfo addDocuments(String uid, String document, String primaryKey)
throws MeilisearchException {
String urlQuery = "/indexes/" + uid + "/documents";
if (primaryKey != null) {
urlQuery += "?primaryKey=" + primaryKey;
}
return httpClient.post(urlQuery, document, Task.class);
return httpClient.post(urlQuery, document, TaskInfo.class);
}

/**
Expand All @@ -123,53 +124,53 @@ Task addDocuments(String uid, String document, String primaryKey) throws Meilise
* @param uid Partial index identifier for the document
* @param document String containing the document to replace the existing document
* @param primaryKey PrimaryKey of the document
* @return Meilisearch's Task API response
* @return Meilisearch's TaskInfo API response
* @throws MeilisearchException if the client request causes an error
*/
Task updateDocuments(String uid, String document, String primaryKey)
TaskInfo updateDocuments(String uid, String document, String primaryKey)
throws MeilisearchException {
String urlPath = "/indexes/" + uid + "/documents";
if (primaryKey != null) {
urlPath += "?primaryKey=" + primaryKey;
}
return httpClient.put(urlPath, document, Task.class);
return httpClient.put(urlPath, document, TaskInfo.class);
}

/**
* Deletes the document at the specified index uid with the specified identifier
*
* @param uid Partial index identifier for the requested document
* @param identifier ID of the document
* @return Meilisearch's Task API response
* @return Meilisearch's TaskInfo API response
* @throws MeilisearchException if the client request causes an error
*/
Task deleteDocument(String uid, String identifier) throws MeilisearchException {
TaskInfo deleteDocument(String uid, String identifier) throws MeilisearchException {
String urlPath = "/indexes/" + uid + "/documents/" + identifier;
return httpClient.delete(urlPath, Task.class);
return httpClient.delete(urlPath, TaskInfo.class);
}

/**
* Deletes the documents at the specified index uid with the specified identifiers
*
* @param uid Partial index identifier for the requested documents
* @param identifiers ID of documents to delete
* @return Meilisearch's Task API response
* @return Meilisearch's TaskInfo API response
* @throws MeilisearchException if the client request causes an error
*/
Task deleteDocuments(String uid, List<String> identifiers) throws MeilisearchException {
TaskInfo deleteDocuments(String uid, List<String> identifiers) throws MeilisearchException {
String urlPath = "/indexes/" + uid + "/documents/" + "delete-batch";
return httpClient.post(urlPath, identifiers, Task.class);
return httpClient.post(urlPath, identifiers, TaskInfo.class);
}

/**
* Deletes all documents at the specified index uid
*
* @param uid Partial index identifier for the requested documents
* @return Meilisearch's Task API response
* @return Meilisearch's TaskInfo API response
* @throws MeilisearchException if the client request causes an error
*/
Task deleteAllDocuments(String uid) throws MeilisearchException {
TaskInfo deleteAllDocuments(String uid) throws MeilisearchException {
String urlPath = "/indexes/" + uid + "/documents";
return httpClient.delete(urlPath, Task.class);
return httpClient.delete(urlPath, TaskInfo.class);
}
}
Loading

0 comments on commit 9abd107

Please sign in to comment.