Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ get_all_tasks_1: |-
client.getTasks();
get_task_1: |-
client.getTask(1);
get_task_documents_1: |-
client.getTaskDocuments(1);
delete_tasks_1: |-
DeleteTasksQuery query = new DeleteTasksQuery().setUids(new int[] {1, 2})
client.deleteTasks(query);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/meilisearch/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,19 @@ public Task getTask(int uid) throws MeilisearchException {
return this.tasksHandler.getTask(uid);
}

/**
* Retrieves the documents of a task with the specified uid
*
* @param uid Identifier of the requested Task
* @return Meilisearch API response as NDJSON String
* @throws MeilisearchException if an error occurs
* @see <a href="https://www.meilisearch.com/docs/reference/api/tasks#get-task-documents">API
* specification</a>
*/
public String getTaskDocuments(int uid) throws MeilisearchException {
return this.tasksHandler.getTaskDocuments(uid);
}

/**
* Retrieves list of tasks
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/meilisearch/sdk/SearchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class SearchRequest {
protected Hybrid hybrid;
protected Double[] vector;
protected Boolean retrieveVectors;

/**
* Constructor for SearchRequest for building search queries with the default values: offset: 0,
* limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/meilisearch/sdk/SettingsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ TaskInfo updateSortableAttributesSettings(String uid, String[] sortableAttribute
: sortableAttributes,
TaskInfo.class);
}

/**
* Resets the sortable attributes of the index
*
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/meilisearch/sdk/TasksHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ Task getTask(int taskUid) throws MeilisearchException {
return httpClient.get(urlPath, Task.class);
}

/**
* Retrieves the documents of a task with the specified task uid
*
* @param taskUid Identifier of the requested Task
* @return String (NDJSON) of documents processed by the task
* @throws MeilisearchException if client request causes an error
*/
String getTaskDocuments(int taskUid) throws MeilisearchException {
URLBuilder urlb = new URLBuilder();
urlb.addSubroute("tasks").addSubroute(Integer.toString(taskUid)).addSubroute("documents");
String urlPath = urlb.getURL();
return httpClient.get(urlPath, String.class);
}

/**
* Retrieves all tasks from the client
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public JacksonJsonHandler() {
registerFilterableAttributesModule(this.mapper);
}

/** @param mapper ObjectMapper */
/**
* @param mapper ObjectMapper
*/
public JacksonJsonHandler(ObjectMapper mapper) {
this.mapper = mapper;
registerFilterableAttributesModule(this.mapper);
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/meilisearch/integration/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,25 @@ public void testCompactWithDocuments() throws Exception {
assertThat(index.getDocument("1", Movie.class).getTitle(), is(equalTo("Document1")));
assertThat(index.getDocument("2", Movie.class).getTitle(), is(equalTo("Document2")));
}

/** Test getTaskDocuments */
@Test
public void testGetTaskDocuments() throws Exception {
String indexUid = "GetTaskDocuments";
Index index = createEmptyIndex(indexUid, this.primaryKey);

TaskInfo addTask =
index.addDocuments("[{" + "\"id\": 1," + "\"title\": \"Document1\"" + "}]");
index.waitForTask(addTask.getTaskUid());
String taskDocuments = client.getTaskDocuments(addTask.getTaskUid());

assertThat(taskDocuments, is(notNullValue()));
String[] lines = taskDocuments.split("\n");
assertThat(lines.length, is(greaterThan(0)));
JsonObject firstDocument = JsonParser.parseString(lines[0]).getAsJsonObject();
assertThat(firstDocument.has("id"), is(true));
assertThat(firstDocument.has("title"), is(true));
assertThat(firstDocument.get("id").getAsInt(), is(equalTo(1)));
assertThat(firstDocument.get("title").getAsString(), is(equalTo("Document1")));
}
}