Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply tasks changes #510

Merged
merged 3 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can apply the URLBuilder here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this one will be changed during PR about documents changes

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);
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/meilisearch/sdk/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.meilisearch.sdk.model.SearchResult;
import com.meilisearch.sdk.model.Settings;
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 com.meilisearch.sdk.model.TypoTolerance;
import java.io.Serializable;
import java.util.ArrayList;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/meilisearch/sdk/IndexesHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.meilisearch.sdk;

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

/**
Expand Down Expand Up @@ -29,7 +29,7 @@ class IndexesHandler {
* @return Meilisearch API response
* @throws MeilisearchException if an error occurs
*/
Task create(String uid) throws MeilisearchException {
TaskInfo create(String uid) throws MeilisearchException {
return this.create(uid, null);
}

Expand All @@ -41,12 +41,12 @@ Task create(String uid) throws MeilisearchException {
* @return Meilisearch API response
* @throws MeilisearchException if an error occurs
*/
Task create(String uid, String primaryKey) throws MeilisearchException {
TaskInfo create(String uid, String primaryKey) throws MeilisearchException {
HashMap<String, String> index = new HashMap<String, String>();
index.put("uid", uid);
index.put("primaryKey", primaryKey);

return httpClient.post("/indexes", index, Task.class);
return httpClient.post("/indexes", index, TaskInfo.class);
}

/**
Expand Down Expand Up @@ -79,12 +79,12 @@ String getAll() throws MeilisearchException {
* @return Meilisearch API response
* @throws MeilisearchException if an error occurs
*/
Task updatePrimaryKey(String uid, String primaryKey) throws MeilisearchException {
TaskInfo updatePrimaryKey(String uid, String primaryKey) throws MeilisearchException {
HashMap<String, String> index = new HashMap<String, String>();
index.put("primaryKey", primaryKey);

String requestQuery = "/indexes/" + uid;
return httpClient.patch(requestQuery, index, Task.class);
return httpClient.patch(requestQuery, index, TaskInfo.class);
}

/**
Expand All @@ -94,8 +94,8 @@ Task updatePrimaryKey(String uid, String primaryKey) throws MeilisearchException
* @return Meilisearch API response
* @throws MeilisearchException if an error occurs
*/
Task delete(String uid) throws MeilisearchException {
TaskInfo delete(String uid) throws MeilisearchException {
String requestQuery = "/indexes/" + uid;
return httpClient.delete(requestQuery, Task.class);
return httpClient.delete(requestQuery, TaskInfo.class);
}
}
Loading