From a79f2be014f1b61aa8475e08b650814aca25cf1f Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 28 Dec 2022 15:44:40 +0100 Subject: [PATCH 01/14] Apply documents changes --- .../java/com/meilisearch/sdk/Documents.java | 189 +++++++++++++----- src/main/java/com/meilisearch/sdk/Index.java | 88 ++++++-- .../meilisearch/sdk/model/DocumentsQuery.java | 21 ++ .../integration/DocumentsTest.java | 116 ++++++++--- 4 files changed, 315 insertions(+), 99 deletions(-) create mode 100644 src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index 7e328901..c710ec8b 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -1,8 +1,9 @@ package com.meilisearch.sdk; -import static java.util.Collections.singletonList; - import com.meilisearch.sdk.exceptions.MeilisearchException; +import com.meilisearch.sdk.http.URLBuilder; +import com.meilisearch.sdk.model.DocumentsQuery; +import com.meilisearch.sdk.model.Results; import com.meilisearch.sdk.model.TaskInfo; import java.util.List; @@ -21,82 +22,162 @@ protected Documents(Config config) { /** * Retrieves the document at the specified index uid with the specified identifier * + * @param Type of the document returned * @param uid Partial index identifier for the requested documents * @param identifier ID of the document - * @return String containing the requested document + * @param targetClass Class of the document returned + * @return Object containing the requested document + * @throws MeilisearchException if the client request causes an error + */ + T getDocument(String uid, String identifier, Class targetClass) + throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute(identifier); + String urlPath = urlb.getURL(); + return httpClient.get(urlPath, targetClass); + } + + /** + * Retrieves the document at the specified index uid with the specified identifier + * + * @param uid Partial index identifier for the requested documents + * @param identifier ID of the document + * @param param accept by the documents route + * @param targetClass Class of the document returned + * @return Object containing the requested document * @throws MeilisearchException if client request causes an error */ - String getDocument(String uid, String identifier) throws MeilisearchException { - String urlPath = "/indexes/" + uid + "/documents/" + identifier; - return httpClient.get(urlPath, String.class); + T getDocument(String uid, String identifier, DocumentsQuery param, Class targetClass) + throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute(identifier) + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()) + .addParameter("fields", param.getFields()); + String urlQuery = urlb.getURL(); + return httpClient.get(urlQuery, targetClass); } /** - * Retrieves the document at the specified index + * Retrieves the document at the specified index uid with the specified identifier * * @param uid Partial index identifier for the requested documents + * @param identifier ID of the document * @return String containing the requested document - * @throws MeilisearchException if the client request causes an error + * @throws MeilisearchException if client request causes an error */ - String getDocuments(String uid) throws MeilisearchException { - String urlPath = "/indexes/" + uid + "/documents"; + String getRawDocument(String uid, String identifier) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute(identifier); + String urlPath = urlb.getURL(); return httpClient.get(urlPath, String.class); } /** - * Retrieves the document at the specified index + * Retrieves the document at the specified index uid with the specified identifier * * @param uid Partial index identifier for the requested documents - * @param limit Limit on the requested documents to be returned + * @param identifier ID of the document + * @param param accept by the documents route * @return String containing the requested document - * @throws MeilisearchException if the client request causes an error + * @throws MeilisearchException if client request causes an error */ - String getDocuments(String uid, int limit) throws MeilisearchException { - String urlQuery = "/indexes/" + uid + "/documents?limit=" + limit; + String getRawDocument(String uid, String identifier, DocumentsQuery param) + throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute(identifier) + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()) + .addParameter("fields", param.getFields()); + String urlQuery = urlb.getURL(); return httpClient.get(urlQuery, String.class); } /** * Retrieves the document at the specified index * + * @param Type of documents returned * @param uid Partial index identifier for the requested documents - * @param limit Limit on the requested documents to be returned - * @param offset Specify the offset of the first hit to return - * @return String containing the requested document + * @param targetClass Class of documents returned + * @return Object containing the requested document * @throws MeilisearchException if the client request causes an error */ - String getDocuments(String uid, int limit, int offset) throws MeilisearchException { - String urlQuery = "/indexes/" + uid + "/documents?limit=" + limit + "&offset=" + offset; - return httpClient.get(urlQuery, String.class); + Results getDocuments(String uid, Class targetClass) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); + String urlPath = urlb.getURL(); + Results documents = httpClient.get(urlPath, Results.class, targetClass); + return documents; } /** * Retrieves the document at the specified index * + * @param Type of documents returned * @param uid Partial index identifier for the requested documents - * @param limit Limit on the requested documents to be returned - * @param offset Specify the offset of the first hit to return - * @param attributesToRetrieve Document attributes to show - * @return String containing the requested document + * @param param accept by the documents route + * @param targetClass Class of documents returned + * @return Object containing the requested document * @throws MeilisearchException if the client request causes an error */ - String getDocuments(String uid, int limit, int offset, List attributesToRetrieve) + Results getDocuments(String uid, DocumentsQuery param, Class targetClass) throws MeilisearchException { - if (attributesToRetrieve == null || attributesToRetrieve.size() == 0) { - attributesToRetrieve = singletonList("*"); - } + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()) + .addParameter("fields", param.getFields()); + String urlQuery = urlb.getURL(); + + Results documents = httpClient.get(urlQuery, Results.class, targetClass); + return documents; + } - String attributesToRetrieveCommaSeparated = String.join(",", attributesToRetrieve); - String urlQuery = - "/indexes/" - + uid - + "/documents?limit=" - + limit - + "&offset=" - + offset - + "&attributesToRetrieve=" - + attributesToRetrieveCommaSeparated; + /** + * Retrieves the document as String at the specified index + * + * @param uid Partial index identifier for the requested documents + * @return Meilisearch API response + * @throws MeilisearchException if an error occurs + */ + String getRawDocuments(String uid) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); + String urlPath = urlb.getURL(); + return httpClient.get(urlPath, String.class); + } + /** + * Retrieves the document as String at the specified index + * + * @param uid Partial index identifier for the requested documents + * @param param accept by the documents route + * @return Meilisearch API response + * @throws MeilisearchException if an error occurs + */ + String getRawDocuments(String uid, DocumentsQuery param) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()) + .addParameter("fields", param.getFields()); + String urlQuery = urlb.getURL(); return httpClient.get(urlQuery, String.class); } @@ -111,10 +192,12 @@ String getDocuments(String uid, int limit, int offset, List attributesTo */ TaskInfo addDocuments(String uid, String document, String primaryKey) throws MeilisearchException { - String urlQuery = "/indexes/" + uid + "/documents"; + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); if (primaryKey != null) { - urlQuery += "?primaryKey=" + primaryKey; + urlb.addParameter("primaryKey", primaryKey); } + String urlQuery = urlb.getURL(); return httpClient.post(urlQuery, document, TaskInfo.class); } @@ -129,10 +212,12 @@ TaskInfo addDocuments(String uid, String document, String primaryKey) */ TaskInfo updateDocuments(String uid, String document, String primaryKey) throws MeilisearchException { - String urlPath = "/indexes/" + uid + "/documents"; + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); if (primaryKey != null) { - urlPath += "?primaryKey=" + primaryKey; + urlb.addParameter("primaryKey", primaryKey); } + String urlPath = urlb.getURL(); return httpClient.put(urlPath, document, TaskInfo.class); } @@ -145,7 +230,12 @@ TaskInfo updateDocuments(String uid, String document, String primaryKey) * @throws MeilisearchException if the client request causes an error */ TaskInfo deleteDocument(String uid, String identifier) throws MeilisearchException { - String urlPath = "/indexes/" + uid + "/documents/" + identifier; + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute(identifier); + String urlPath = urlb.getURL(); return httpClient.delete(urlPath, TaskInfo.class); } @@ -158,7 +248,12 @@ TaskInfo deleteDocument(String uid, String identifier) throws MeilisearchExcepti * @throws MeilisearchException if the client request causes an error */ TaskInfo deleteDocuments(String uid, List identifiers) throws MeilisearchException { - String urlPath = "/indexes/" + uid + "/documents/" + "delete-batch"; + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute("delete-batch"); + String urlPath = urlb.getURL(); return httpClient.post(urlPath, identifiers, TaskInfo.class); } @@ -170,7 +265,9 @@ TaskInfo deleteDocuments(String uid, List identifiers) throws Meilisearc * @throws MeilisearchException if the client request causes an error */ TaskInfo deleteAllDocuments(String uid) throws MeilisearchException { - String urlPath = "/indexes/" + uid + "/documents"; + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); + String urlPath = urlb.getURL(); return httpClient.delete(urlPath, TaskInfo.class); } } diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index cd6933dd..7a874298 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -1,7 +1,9 @@ package com.meilisearch.sdk; import com.meilisearch.sdk.exceptions.MeilisearchException; +import com.meilisearch.sdk.model.DocumentsQuery; import com.meilisearch.sdk.model.IndexStats; +import com.meilisearch.sdk.model.Results; import com.meilisearch.sdk.model.SearchResult; import com.meilisearch.sdk.model.Settings; import com.meilisearch.sdk.model.Task; @@ -49,63 +51,107 @@ void setConfig(Config config) { * Gets a documents with the specified uid Refer * https://docs.meilisearch.com/reference/api/documents.html#get-one-document * + * @param Type of documents returned * @param identifier Identifier of the document to get + * @param targetClass Class of the document returned * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - public String getDocument(String identifier) throws MeilisearchException { - return this.documents.getDocument(this.uid, identifier); + public T getDocument(String identifier, Class targetClass) throws MeilisearchException { + return this.documents.getDocument(this.uid, identifier, targetClass); } /** - * Gets documenta at the specified index Refer + * Gets a documents with the specified uid Refer + * https://docs.meilisearch.com/reference/api/documents.html#get-one-document + * + * @param Type of documents returned + * @param identifier Identifier of the document to get + * @param param accept by the documents route + * @param targetClass Class of documents returned + * @return Meilisearch API response + * @throws MeilisearchException if an error occurs + */ + public T getDocument(String identifier, DocumentsQuery param, Class targetClass) + throws MeilisearchException { + return this.documents.getDocument(this.uid, identifier, param, targetClass); + } + + /** + * Gets a documents with the specified uid Refer + * https://docs.meilisearch.com/reference/api/documents.html#get-one-document + * + * @param identifier Identifier of the document to get + * @return Meilisearch API response + * @throws MeilisearchException if an error occurs + */ + public String getRawDocument(String identifier) throws MeilisearchException { + return this.documents.getRawDocument(this.uid, identifier); + } + + /** + * Gets a documents with the specified uid Refer + * https://docs.meilisearch.com/reference/api/documents.html#get-one-document + * + * @param identifier Identifier of the document to get + * @param param accept by the documents route + * @return Meilisearch API response + * @throws MeilisearchException if an error occurs + */ + public String getRawDocument(String identifier, DocumentsQuery param) + throws MeilisearchException { + return this.documents.getRawDocument(this.uid, identifier, param); + } + + /** + * Gets documents at the specified index Refer * https://docs.meilisearch.com/reference/api/documents.html#get-documents * + * @param Type of documents returned + * @param targetClass Class of documents returned * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - public String getDocuments() throws MeilisearchException { - return this.documents.getDocuments(this.uid); + public Results getDocuments(Class targetClass) throws MeilisearchException { + return this.documents.getDocuments(this.uid, targetClass); } /** - * Gets documents at the specified index and limit the number of documents returned Refer + * Gets documents at the specified index Refer * https://docs.meilisearch.com/reference/api/documents.html#get-documents * - * @param limits Maximum amount of documents to return + * @param Type of documents returned + * @param param accept by the documents route + * @param targetClass Class of documents returned * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - public String getDocuments(int limits) throws MeilisearchException { - return this.documents.getDocuments(this.uid, limits); + public Results getDocuments(DocumentsQuery param, Class targetClass) + throws MeilisearchException { + return this.documents.getDocuments(this.uid, param, targetClass); } /** - * Gets documents at the specified index and limit the number of documents returned Refer + * Gets documents as String at the specified index Refer * https://docs.meilisearch.com/reference/api/documents.html#get-documents * - * @param limits Maximum amount of documents to return - * @param offset Number of documents to skip * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - public String getDocuments(int limits, int offset) throws MeilisearchException { - return this.documents.getDocuments(this.uid, limits, offset); + public String getRawDocuments() throws MeilisearchException { + return this.documents.getRawDocuments(this.uid); } /** - * Gets documents at the specified index and limit the number of documents returned Refer + * Gets documents as String at the specified index Refer * https://docs.meilisearch.com/reference/api/documents.html#get-documents * - * @param limits Maximum amount of documents to return - * @param offset Number of documents to skip - * @param attributesToRetrieve Document attributes to show + * @param param accept by the documents route * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - public String getDocuments(int limits, int offset, List attributesToRetrieve) - throws MeilisearchException { - return this.documents.getDocuments(this.uid, limits, offset, attributesToRetrieve); + public String getRawDocuments(DocumentsQuery param) throws MeilisearchException { + return this.documents.getRawDocuments(this.uid, param); } /** diff --git a/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java b/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java new file mode 100644 index 00000000..1b5d123d --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java @@ -0,0 +1,21 @@ +package com.meilisearch.sdk.model; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +/** + * Data structure of a query parameter for documents route + * + *

https://docs.meilisearch.com/reference/api/documents.html#query-parameters + */ +@Setter +@Getter +@Accessors(chain = true) +public class DocumentsQuery { + private int offset = -1; + private int limit = -1; + private String[] fields; + + public DocumentsQuery() {} +} diff --git a/src/test/java/com/meilisearch/integration/DocumentsTest.java b/src/test/java/com/meilisearch/integration/DocumentsTest.java index 64bbe146..9ba3bbda 100644 --- a/src/test/java/com/meilisearch/integration/DocumentsTest.java +++ b/src/test/java/com/meilisearch/integration/DocumentsTest.java @@ -1,6 +1,5 @@ package com.meilisearch.integration; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.*; import com.google.gson.JsonObject; @@ -8,19 +7,18 @@ import com.meilisearch.integration.classes.TestData; import com.meilisearch.sdk.Index; import com.meilisearch.sdk.exceptions.MeilisearchApiException; +import com.meilisearch.sdk.model.DocumentsQuery; +import com.meilisearch.sdk.model.Results; import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.utils.Movie; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Stream; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; @Tag("integration") public class DocumentsTest extends AbstractIT { @@ -47,6 +45,8 @@ public void testAddDocumentsSingle() throws Exception { TaskInfo task = index.addDocuments("[" + singleDocument + "]"); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); assertEquals(1, movies.length); assertEquals("419704", movies[0].getId()); @@ -85,7 +85,8 @@ public void testAddDocumentsWithSuppliedPrimaryKey() throws Exception { TaskInfo firstTask = index.addDocuments("[" + firstDocument + "]", "language"); index.waitForTask(firstTask.getTaskUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); assertEquals(1, movies.length); assertEquals("419704", movies[0].getId()); assertEquals("Ad Astra", movies[0].getTitle()); @@ -93,7 +94,7 @@ public void testAddDocumentsWithSuppliedPrimaryKey() throws Exception { TaskInfo secondTask = index.addDocuments("[" + secondDocument + "]", "language"); index.waitForTask(secondTask.getTaskUid()); - movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + movies = (Movie[]) index.getDocuments(Movie.class).getResults(); assertEquals(1, movies.length); assertEquals("574982", movies[0].getId()); assertEquals("The Blackout", movies[0].getTitle()); @@ -110,10 +111,10 @@ public void testAddDocumentsMultiple() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); for (int i = 0; i < movies.length; i++) { - Movie movie = - this.gson.fromJson( - index.getDocument(testData.getData().get(i).getId()), Movie.class); + Movie movie = index.getDocument(testData.getData().get(i).getId(), Movie.class); assertEquals(movie.getTitle(), testData.getData().get(i).getTitle()); } } @@ -129,10 +130,10 @@ public void testAddDocumentsMultipleWithJacksonJsonHandler() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); for (int i = 0; i < movies.length; i++) { - Movie movie = - this.gson.fromJson( - index.getDocument(testData.getData().get(i).getId()), Movie.class); + Movie movie = index.getDocument(testData.getData().get(i).getId(), Movie.class); assertEquals(movie.getTitle(), testData.getData().get(i).getTitle()); } } @@ -184,6 +185,8 @@ public void testUpdateDocument() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); Movie toUpdate = movies[0]; toUpdate.setTitle("The Perks of Being a Wallflower"); toUpdate.setOverview("The best movie I've ever seen"); @@ -191,7 +194,7 @@ public void testUpdateDocument() throws Exception { task = index.updateDocuments("[" + this.gson.toJson(toUpdate) + "]"); index.waitForTask(task.getTaskUid()); - Movie responseUpdate = this.gson.fromJson(index.getDocument(toUpdate.getId()), Movie.class); + Movie responseUpdate = index.getDocument(toUpdate.getId(), Movie.class); assertEquals(toUpdate.getTitle(), responseUpdate.getTitle()); assertEquals(toUpdate.getOverview(), responseUpdate.getOverview()); @@ -219,7 +222,8 @@ public void testUpdateDocumentsWithSuppliedPrimaryKey() throws Exception { TaskInfo firstTask = index.updateDocuments("[" + firstDocument + "]", "language"); index.waitForTask(firstTask.getTaskUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); assertEquals(1, movies.length); assertEquals("419704", movies[0].getId()); assertEquals("Ad Astra", movies[0].getTitle()); @@ -243,6 +247,8 @@ public void testUpdateDocuments() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); List toUpdate = new ArrayList<>(); for (int i = 0; i < 5; i++) { movies[i].setTitle("Star wars episode: " + i); @@ -254,8 +260,7 @@ public void testUpdateDocuments() throws Exception { index.waitForTask(task.getTaskUid()); for (int j = 0; j < 5; j++) { - Movie responseUpdate = - this.gson.fromJson(index.getDocument(toUpdate.get(j).getId()), Movie.class); + Movie responseUpdate = index.getDocument(toUpdate.get(j).getId(), Movie.class); assertEquals(toUpdate.get(j).getTitle(), responseUpdate.getTitle()); assertEquals(toUpdate.get(j).getOverview(), responseUpdate.getOverview()); } @@ -272,6 +277,8 @@ public void testUpdateDocumentsInBatchesWithBatchSize() throws Exception { TaskInfo taskIndex = index.addDocuments(testData.getRaw()); index.waitForTask(taskIndex.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); List toUpdate = new ArrayList<>(); for (int i = 0; i < 5; i++) { movies[i].setTitle("Star wars episode: " + i); @@ -298,6 +305,8 @@ public void testUpdateDocumentsInBatches() throws Exception { TaskInfo taskIndex = index.addDocuments(testData.getRaw()); index.waitForTask(taskIndex.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); List toUpdate = new ArrayList<>(); for (int i = 0; i < 5; i++) { movies[i].setTitle("Star wars episode: " + i); @@ -323,10 +332,25 @@ public void testGetDocument() throws Exception { TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); + Movie movie = index.getDocument(testData.getData().get(0).getId(), Movie.class); + assertEquals(movie.getTitle(), testData.getData().get(0).getTitle()); + } + + /** Test default GetRawDocuments */ + @Test + public void testGetRawDocument() throws Exception { + + String indexUid = "GetRawDocument"; + Index index = client.index(indexUid); + + TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); + TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); Movie movie = this.gson.fromJson( - index.getDocument(testData.getData().get(0).getId()), Movie.class); + index.getRawDocument(testData.getData().get(0).getId()), Movie.class); assertEquals(movie.getTitle(), testData.getData().get(0).getTitle()); } @@ -341,11 +365,20 @@ public void testGetDocuments() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); + assertEquals(20, movies.length); for (int i = 0; i < movies.length; i++) { - Movie movie = - this.gson.fromJson( - index.getDocument(testData.getData().get(i).getId()), Movie.class); + assertEquals(movies[i].getTitle(), testData.getData().get(i).getTitle()); + String[] expectedGenres = testData.getData().get(i).getGenres(); + String[] foundGenres = movies[i].getGenres(); + for (int x = 0; x < expectedGenres.length; x++) { + assertEquals(expectedGenres[x], foundGenres[x]); + } + } + for (int i = 0; i < movies.length; i++) { + Movie movie = index.getDocument(testData.getData().get(i).getId(), Movie.class); assertEquals(movie.getTitle(), testData.getData().get(i).getTitle()); String[] expectedGenres = testData.getData().get(i).getGenres(); String[] foundGenres = movie.getGenres(); @@ -361,17 +394,18 @@ public void testGetDocumentsLimit() throws Exception { String indexUid = "GetDocumentsLimit"; int limit = 24; + DocumentsQuery query = new DocumentsQuery().setLimit(limit); Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(query, Movie.class); + Movie[] movies = result.getResults(); assertEquals(limit, movies.length); for (int i = 0; i < movies.length; i++) { - Movie movie = - this.gson.fromJson( - index.getDocument(testData.getData().get(i).getId()), Movie.class); + Movie movie = index.getDocument(testData.getData().get(i).getId(), Movie.class); assertEquals(movie.getTitle(), testData.getData().get(i).getTitle()); } } @@ -383,12 +417,18 @@ public void testGetDocumentsLimitAndOffset() throws Exception { int limit = 2; int offset = 2; int secondOffset = 5; + DocumentsQuery query = new DocumentsQuery().setLimit(limit).setOffset(offset); Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(query, Movie.class); + Movie[] movies = result.getResults(); + Results secondResults = + index.getDocuments(query.setOffset(secondOffset), Movie.class); + Movie[] secondMovies = secondResults.getResults(); assertEquals(limit, movies.length); assertEquals(limit, secondMovies.length); @@ -399,17 +439,24 @@ public void testGetDocumentsLimitAndOffset() throws Exception { /** Test GetDocuments with limit, offset and specified fields */ @Test - public void testGetDocumentsLimitAndOffsetAndSpecifiedAttributesToRetrieve() throws Exception { - String indexUid = "GetDocumentsLimit"; + public void testGetDocumentsLimitAndOffsetAndSpecifiedFields() throws Exception { + String indexUid = "GetDocumentsLimitAndOffsetAndSpecifiedFields"; int limit = 2; int offset = 2; - List attributesToRetrieve = Arrays.asList("id", "title"); + List fields = Arrays.asList("id", "title"); + DocumentsQuery query = + new DocumentsQuery() + .setLimit(limit) + .setOffset(offset) + .setFields(fields.toArray(new String[0])); Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(query, Movie.class); + Movie[] movies = result.getResults(); assertEquals(limit, movies.length); @@ -467,12 +514,15 @@ public void testDeleteDocument() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); Movie toDelete = movies[0]; task = index.deleteDocument(toDelete.getId()); index.waitForTask(task.getTaskUid()); - assertThrows(MeilisearchApiException.class, () -> index.getDocument(toDelete.getId())); + assertThrows( + MeilisearchApiException.class, + () -> index.getDocument(toDelete.getId(), Movie.class)); } /** Test deleteDocuments */ @@ -486,7 +536,8 @@ public void testDeleteDocuments() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); assertEquals(20, movies.length); List identifiersToDelete = getIdentifiersToDelete(movies); @@ -494,7 +545,7 @@ public void testDeleteDocuments() throws Exception { task = index.deleteDocuments(identifiersToDelete); index.waitForTask(task.getTaskUid()); - movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + movies = (Movie[]) index.getDocuments(Movie.class).getResults(); boolean containsDeletedMovie = Arrays.stream(movies) @@ -519,7 +570,8 @@ public void testDeleteAllDocuments() throws Exception { TaskInfo taskIndex = index.addDocuments(testData.getRaw()); index.waitForTask(taskIndex.getTaskUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); assertEquals(20, movies.length); TaskInfo task = index.deleteAllDocuments(); @@ -529,7 +581,7 @@ public void testDeleteAllDocuments() throws Exception { assertEquals(task.getType(), "documentDeletion"); assertNotNull(task.getEnqueuedAt()); - movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + movies = (Movie[]) index.getDocuments(Movie.class).getResults(); assertEquals(0, movies.length); } } From 911c1556b2da4b69a0ac564ddf6950b101827306 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 28 Dec 2022 17:41:49 +0100 Subject: [PATCH 02/14] Add tests for getRawDocuments --- .../integration/DocumentsTest.java | 104 ++++++++++++++---- 1 file changed, 82 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/meilisearch/integration/DocumentsTest.java b/src/test/java/com/meilisearch/integration/DocumentsTest.java index 9ba3bbda..7dbab16c 100644 --- a/src/test/java/com/meilisearch/integration/DocumentsTest.java +++ b/src/test/java/com/meilisearch/integration/DocumentsTest.java @@ -470,37 +470,97 @@ public void testGetDocumentsLimitAndOffsetAndSpecifiedFields() throws Exception assertNull(movies[0].getRelease_date()); } - /** Test GetDocuments with limit, offset and attributesToRetrieve */ - @ParameterizedTest - @MethodSource("attributesToRetrieve") - public void testGetDocumentsLimitAndOffsetAndAttributesToRetrieve( - List attributesToRetrieve) throws Exception { - String indexUid = "GetDocumentsLimit"; + /** Test default GetRawDocuments */ + @Test + public void testGetRawDocuments() throws Exception { + String indexUid = "GetRawDocuments"; + Index index = client.index(indexUid); + + TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); + TaskInfo task = index.addDocuments(testData.getRaw()); + + index.waitForTask(task.getTaskUid()); + String results = index.getRawDocuments(); + + assertTrue(results.contains("results")); + assertTrue(results.contains(testData.getData().get(0).getId())); + assertTrue(results.contains(testData.getData().get(0).getTitle())); + assertTrue(results.contains(testData.getData().get(0).getGenres()[0])); + assertTrue(results.contains(testData.getData().get(0).getLanguage())); + assertTrue(results.contains(testData.getData().get(0).getOverview())); + assertTrue(results.contains(testData.getData().get(0).getPoster())); + assertTrue(results.contains(testData.getData().get(0).getRelease_date())); + } + + /** Test GetRawDocuments with limit */ + @Test + public void testGetRawDocumentsLimit() throws Exception { + + String indexUid = "GetRawDocumentsLimit"; + int limit = 24; + DocumentsQuery query = new DocumentsQuery().setLimit(limit); + Index index = client.index(indexUid); + + TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); + TaskInfo task = index.addDocuments(testData.getRaw()); + + index.waitForTask(task.getTaskUid()); + String results = index.getRawDocuments(query); + + assertTrue(results.contains("results")); + assertTrue(results.contains("\"limit\":24")); + } + + /** Test GetRawDocuments with limit and offset */ + @Test + public void testGetRawDocumentsLimitAndOffset() throws Exception { + String indexUid = "GetRawDocumentsLimitAndOffset"; int limit = 2; int offset = 2; + int secondOffset = 5; + DocumentsQuery query = new DocumentsQuery().setLimit(limit).setOffset(offset); Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); - - index.waitForTask(task.getUid()); - Movie[] movies = - this.gson.fromJson( - index.getDocuments(limit, offset, attributesToRetrieve), Movie[].class); + TaskInfo task = index.addDocuments(testData.getRaw()); - assertEquals(limit, movies.length); + index.waitForTask(task.getTaskUid()); + String results = index.getRawDocuments(query); - assertNotNull(movies[0].getId()); - assertNotNull(movies[0].getTitle()); - assertNotNull(movies[0].getGenres()); - assertNotNull(movies[0].getLanguage()); - assertNotNull(movies[0].getOverview()); - assertNotNull(movies[0].getPoster()); - assertNotNull(movies[0].getRelease_date()); + assertTrue(results.contains("results")); + assertTrue(results.contains("\"limit\":2")); + assertTrue(results.contains("\"offset\":2")); } - private static Stream> attributesToRetrieve() { - return Stream.of(emptyList(), null); + /** Test GetRawDocuments with limit, offset and specified fields */ + @Test + public void testGetRawDocumentsLimitAndOffsetAndSpecifiedFields() throws Exception { + String indexUid = "GetRawDocumentsLimitAndOffsetAndSpecifiedFields"; + int limit = 2; + int offset = 2; + List fields = Arrays.asList("id", "title"); + DocumentsQuery query = + new DocumentsQuery() + .setLimit(limit) + .setOffset(offset) + .setFields(fields.toArray(new String[0])); + Index index = client.index(indexUid); + + TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); + TaskInfo task = index.addDocuments(testData.getRaw()); + + index.waitForTask(task.getTaskUid()); + String results = index.getRawDocuments(query); + + assertTrue(results.contains("results")); + assertTrue(results.contains("\"limit\":2")); + assertTrue(results.contains("\"offset\":2")); + assertTrue(results.contains("id")); + assertTrue(results.contains("title")); + assertFalse(results.contains("genres")); + assertFalse(results.contains("langage")); + assertFalse(results.contains("poster")); + assertFalse(results.contains("release_date")); } /** Test deleteDocument */ From 67cd327a4cd80e9cfc9fc6b7b42979b1c4eae486 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 29 Dec 2022 16:15:21 +0100 Subject: [PATCH 03/14] Add toQuery method to simplify code --- .../java/com/meilisearch/sdk/Documents.java | 86 +++---------------- .../meilisearch/sdk/model/DocumentsQuery.java | 39 +++++++++ 2 files changed, 53 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index c710ec8b..e415a743 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -31,13 +31,7 @@ protected Documents(Config config) { */ T getDocument(String uid, String identifier, Class targetClass) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes") - .addSubroute(uid) - .addSubroute("documents") - .addSubroute(identifier); - String urlPath = urlb.getURL(); - return httpClient.get(urlPath, targetClass); + return httpClient.get(new DocumentsQuery().toQuery(uid, identifier), targetClass); } /** @@ -52,16 +46,7 @@ T getDocument(String uid, String identifier, Class targetClass) */ T getDocument(String uid, String identifier, DocumentsQuery param, Class targetClass) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes") - .addSubroute(uid) - .addSubroute("documents") - .addSubroute(identifier) - .addParameter("limit", param.getLimit()) - .addParameter("offset", param.getOffset()) - .addParameter("fields", param.getFields()); - String urlQuery = urlb.getURL(); - return httpClient.get(urlQuery, targetClass); + return httpClient.get(param.toQuery(uid, identifier, param), targetClass); } /** @@ -73,13 +58,7 @@ T getDocument(String uid, String identifier, DocumentsQuery param, Class * @throws MeilisearchException if client request causes an error */ String getRawDocument(String uid, String identifier) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes") - .addSubroute(uid) - .addSubroute("documents") - .addSubroute(identifier); - String urlPath = urlb.getURL(); - return httpClient.get(urlPath, String.class); + return httpClient.get(new DocumentsQuery().toQuery(uid, identifier), String.class); } /** @@ -93,16 +72,7 @@ String getRawDocument(String uid, String identifier) throws MeilisearchException */ String getRawDocument(String uid, String identifier, DocumentsQuery param) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes") - .addSubroute(uid) - .addSubroute("documents") - .addSubroute(identifier) - .addParameter("limit", param.getLimit()) - .addParameter("offset", param.getOffset()) - .addParameter("fields", param.getFields()); - String urlQuery = urlb.getURL(); - return httpClient.get(urlQuery, String.class); + return httpClient.get(param.toQuery(uid, identifier, param), String.class); } /** @@ -115,10 +85,9 @@ String getRawDocument(String uid, String identifier, DocumentsQuery param) * @throws MeilisearchException if the client request causes an error */ Results getDocuments(String uid, Class targetClass) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); - String urlPath = urlb.getURL(); - Results documents = httpClient.get(urlPath, Results.class, targetClass); + Results documents = + httpClient.get( + new DocumentsQuery().toQuery(uid), Results.class, targetClass); return documents; } @@ -134,16 +103,8 @@ Results getDocuments(String uid, Class targetClass) throws Meilisearch */ Results getDocuments(String uid, DocumentsQuery param, Class targetClass) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes") - .addSubroute(uid) - .addSubroute("documents") - .addParameter("limit", param.getLimit()) - .addParameter("offset", param.getOffset()) - .addParameter("fields", param.getFields()); - String urlQuery = urlb.getURL(); - - Results documents = httpClient.get(urlQuery, Results.class, targetClass); + Results documents = + httpClient.get(param.toQuery(uid, param), Results.class, targetClass); return documents; } @@ -155,10 +116,7 @@ Results getDocuments(String uid, DocumentsQuery param, Class targetCla * @throws MeilisearchException if an error occurs */ String getRawDocuments(String uid) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); - String urlPath = urlb.getURL(); - return httpClient.get(urlPath, String.class); + return httpClient.get(new DocumentsQuery().toQuery(uid), String.class); } /** @@ -170,15 +128,7 @@ String getRawDocuments(String uid) throws MeilisearchException { * @throws MeilisearchException if an error occurs */ String getRawDocuments(String uid, DocumentsQuery param) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes") - .addSubroute(uid) - .addSubroute("documents") - .addParameter("limit", param.getLimit()) - .addParameter("offset", param.getOffset()) - .addParameter("fields", param.getFields()); - String urlQuery = urlb.getURL(); - return httpClient.get(urlQuery, String.class); + return httpClient.get(param.toQuery(uid, param), String.class); } /** @@ -230,13 +180,8 @@ TaskInfo updateDocuments(String uid, String document, String primaryKey) * @throws MeilisearchException if the client request causes an error */ TaskInfo deleteDocument(String uid, String identifier) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes") - .addSubroute(uid) - .addSubroute("documents") - .addSubroute(identifier); - String urlPath = urlb.getURL(); - return httpClient.delete(urlPath, TaskInfo.class); + return httpClient.delete( + new DocumentsQuery().toQuery(uid, identifier), TaskInfo.class); } /** @@ -265,9 +210,6 @@ TaskInfo deleteDocuments(String uid, List identifiers) throws Meilisearc * @throws MeilisearchException if the client request causes an error */ TaskInfo deleteAllDocuments(String uid) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); - String urlPath = urlb.getURL(); - return httpClient.delete(urlPath, TaskInfo.class); + return httpClient.delete(new DocumentsQuery().toQuery(uid), TaskInfo.class); } } diff --git a/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java b/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java index 1b5d123d..4f282392 100644 --- a/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java +++ b/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java @@ -1,5 +1,6 @@ package com.meilisearch.sdk.model; +import com.meilisearch.sdk.http.URLBuilder; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -18,4 +19,42 @@ public class DocumentsQuery { private String[] fields; public DocumentsQuery() {} + + public String toQuery(String uid) { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes").addSubroute(uid).addSubroute("documents"); + return urlb.getURL(); + } + + public String toQuery(String uid, String identifier) { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute(identifier); + return urlb.getURL(); + } + + public String toQuery(String uid, DocumentsQuery param) { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()) + .addParameter("fields", param.getFields()); + return urlb.getURL(); + } + + public String toQuery(String uid, String identifier, DocumentsQuery param) { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("indexes") + .addSubroute(uid) + .addSubroute("documents") + .addSubroute(identifier) + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()) + .addParameter("fields", param.getFields()); + return urlb.getURL(); + } } From bf2a43656535e90d935c0314f834c04cb961e8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:43:07 +0100 Subject: [PATCH 04/14] Update src/main/java/com/meilisearch/sdk/Documents.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Documents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index e415a743..8e46c48f 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -123,7 +123,7 @@ String getRawDocuments(String uid) throws MeilisearchException { * Retrieves the document as String at the specified index * * @param uid Partial index identifier for the requested documents - * @param param accept by the documents route + * @param param accepted by the documents route * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ From deb81a0d4922d733880d3e7cc7fac6f2cc8589e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:43:42 +0100 Subject: [PATCH 05/14] Update src/main/java/com/meilisearch/sdk/Index.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Index.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index 7a874298..abd64ea4 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -90,7 +90,7 @@ public String getRawDocument(String identifier) throws MeilisearchException { } /** - * Gets a documents with the specified uid Refer + * Gets a document with the specified uid and parameters * https://docs.meilisearch.com/reference/api/documents.html#get-one-document * * @param identifier Identifier of the document to get From 274efe21f20d336f3646cbbaf728b5cafda3973d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:43:50 +0100 Subject: [PATCH 06/14] Update src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java b/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java index 4f282392..859c8f1a 100644 --- a/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java +++ b/src/main/java/com/meilisearch/sdk/model/DocumentsQuery.java @@ -6,7 +6,7 @@ import lombok.experimental.Accessors; /** - * Data structure of a query parameter for documents route + * Data structure of the query parameters of the documents route * *

https://docs.meilisearch.com/reference/api/documents.html#query-parameters */ From 6c413de2def541c55c02870ea60c338e49b97534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:44:05 +0100 Subject: [PATCH 07/14] Update src/main/java/com/meilisearch/sdk/Documents.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Documents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index 8e46c48f..bec205c7 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -92,7 +92,7 @@ Results getDocuments(String uid, Class targetClass) throws Meilisearch } /** - * Retrieves the document at the specified index + * Gets the document from the specified index * * @param Type of documents returned * @param uid Partial index identifier for the requested documents From 1002a9af3ae2a5b6d05d5b768bfa4d7209c31982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:44:19 +0100 Subject: [PATCH 08/14] Update src/main/java/com/meilisearch/sdk/Index.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Index.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index abd64ea4..08e5ad7b 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -67,7 +67,7 @@ public T getDocument(String identifier, Class targetClass) throws Meilise * * @param Type of documents returned * @param identifier Identifier of the document to get - * @param param accept by the documents route + * @param param accepted by the get document route * @param targetClass Class of documents returned * @return Meilisearch API response * @throws MeilisearchException if an error occurs From 941ab885a588a2c7a48385a0461712cb06c7c840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:44:39 +0100 Subject: [PATCH 09/14] Update src/main/java/com/meilisearch/sdk/Documents.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Documents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index bec205c7..92f9f419 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -96,7 +96,7 @@ Results getDocuments(String uid, Class targetClass) throws Meilisearch * * @param Type of documents returned * @param uid Partial index identifier for the requested documents - * @param param accept by the documents route + * @param param accepted by the get documents route * @param targetClass Class of documents returned * @return Object containing the requested document * @throws MeilisearchException if the client request causes an error From 73f9d0d288cfd83912d1f1727038ea8f2be55026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:44:58 +0100 Subject: [PATCH 10/14] Update src/main/java/com/meilisearch/sdk/Documents.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Documents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index 92f9f419..f9f7eea8 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -39,7 +39,7 @@ T getDocument(String uid, String identifier, Class targetClass) * * @param uid Partial index identifier for the requested documents * @param identifier ID of the document - * @param param accept by the documents route + * @param param accepted by the get document route * @param targetClass Class of the document returned * @return Object containing the requested document * @throws MeilisearchException if client request causes an error From 75aa6926019cf1bff170eb83d266bc50a16f36ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 14:45:19 +0100 Subject: [PATCH 11/14] Update src/main/java/com/meilisearch/sdk/Documents.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Documents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index f9f7eea8..f431d89d 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -35,7 +35,7 @@ T getDocument(String uid, String identifier, Class targetClass) } /** - * Retrieves the document at the specified index uid with the specified identifier + * Retrieves the document from the specified index uid with the specified identifier * * @param uid Partial index identifier for the requested documents * @param identifier ID of the document From 389ebc01431367866b31355f06c208a492aeaee2 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 5 Jan 2023 14:57:31 +0100 Subject: [PATCH 12/14] Improve description of documents's method --- .../java/com/meilisearch/sdk/Documents.java | 18 +++++++++--------- src/main/java/com/meilisearch/sdk/Index.java | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index f431d89d..dabdc33d 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -20,7 +20,7 @@ protected Documents(Config config) { } /** - * Retrieves the document at the specified index uid with the specified identifier + * Retrieves the document from the specified index uid with the specified identifier * * @param Type of the document returned * @param uid Partial index identifier for the requested documents @@ -50,7 +50,7 @@ T getDocument(String uid, String identifier, DocumentsQuery param, Class } /** - * Retrieves the document at the specified index uid with the specified identifier + * Retrieves the document from the specified index uid with the specified identifier * * @param uid Partial index identifier for the requested documents * @param identifier ID of the document @@ -62,7 +62,7 @@ String getRawDocument(String uid, String identifier) throws MeilisearchException } /** - * Retrieves the document at the specified index uid with the specified identifier + * Retrieves the document from the specified index uid with the specified identifier * * @param uid Partial index identifier for the requested documents * @param identifier ID of the document @@ -76,12 +76,12 @@ String getRawDocument(String uid, String identifier, DocumentsQuery param) } /** - * Retrieves the document at the specified index + * Retrieves the document from the specified index * * @param Type of documents returned * @param uid Partial index identifier for the requested documents * @param targetClass Class of documents returned - * @return Object containing the requested document + * @return Results containing a list of Object containing the requested document * @throws MeilisearchException if the client request causes an error */ Results getDocuments(String uid, Class targetClass) throws MeilisearchException { @@ -92,13 +92,13 @@ Results getDocuments(String uid, Class targetClass) throws Meilisearch } /** - * Gets the document from the specified index + * Retrieves the document from the specified index * * @param Type of documents returned * @param uid Partial index identifier for the requested documents * @param param accepted by the get documents route * @param targetClass Class of documents returned - * @return Object containing the requested document + * @return Results containing a list of Object containing the requested document * @throws MeilisearchException if the client request causes an error */ Results getDocuments(String uid, DocumentsQuery param, Class targetClass) @@ -109,7 +109,7 @@ Results getDocuments(String uid, DocumentsQuery param, Class targetCla } /** - * Retrieves the document as String at the specified index + * Retrieves the document as a string from the specified index * * @param uid Partial index identifier for the requested documents * @return Meilisearch API response @@ -172,7 +172,7 @@ TaskInfo updateDocuments(String uid, String document, String primaryKey) } /** - * Deletes the document at the specified index uid with the specified identifier + * Deletes the document from the specified index uid with the specified identifier * * @param uid Partial index identifier for the requested document * @param identifier ID of the document diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index 08e5ad7b..3bd0a482 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -54,7 +54,7 @@ void setConfig(Config config) { * @param Type of documents returned * @param identifier Identifier of the document to get * @param targetClass Class of the document returned - * @return Meilisearch API response + * @return Object containing the requested document * @throws MeilisearchException if an error occurs */ public T getDocument(String identifier, Class targetClass) throws MeilisearchException { @@ -69,7 +69,7 @@ public T getDocument(String identifier, Class targetClass) throws Meilise * @param identifier Identifier of the document to get * @param param accepted by the get document route * @param targetClass Class of documents returned - * @return Meilisearch API response + * @return Object containing the requested document * @throws MeilisearchException if an error occurs */ public T getDocument(String identifier, DocumentsQuery param, Class targetClass) @@ -82,7 +82,7 @@ public T getDocument(String identifier, DocumentsQuery param, Class targe * https://docs.meilisearch.com/reference/api/documents.html#get-one-document * * @param identifier Identifier of the document to get - * @return Meilisearch API response + * @return String containing the requested document * @throws MeilisearchException if an error occurs */ public String getRawDocument(String identifier) throws MeilisearchException { @@ -95,7 +95,7 @@ public String getRawDocument(String identifier) throws MeilisearchException { * * @param identifier Identifier of the document to get * @param param accept by the documents route - * @return Meilisearch API response + * @return String containing the requested document * @throws MeilisearchException if an error occurs */ public String getRawDocument(String identifier, DocumentsQuery param) @@ -109,7 +109,7 @@ public String getRawDocument(String identifier, DocumentsQuery param) * * @param Type of documents returned * @param targetClass Class of documents returned - * @return Meilisearch API response + * @return Results containing a list of Object containing the requested document * @throws MeilisearchException if an error occurs */ public Results getDocuments(Class targetClass) throws MeilisearchException { @@ -123,7 +123,7 @@ public Results getDocuments(Class targetClass) throws MeilisearchExcep * @param Type of documents returned * @param param accept by the documents route * @param targetClass Class of documents returned - * @return Meilisearch API response + * @return Results containing a list of Object containing the requested document * @throws MeilisearchException if an error occurs */ public Results getDocuments(DocumentsQuery param, Class targetClass) @@ -135,7 +135,7 @@ public Results getDocuments(DocumentsQuery param, Class targetClass) * Gets documents as String at the specified index Refer * https://docs.meilisearch.com/reference/api/documents.html#get-documents * - * @return Meilisearch API response + * @return String containing a list of documents * @throws MeilisearchException if an error occurs */ public String getRawDocuments() throws MeilisearchException { @@ -147,7 +147,7 @@ public String getRawDocuments() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/documents.html#get-documents * * @param param accept by the documents route - * @return Meilisearch API response + * @return String containing a list of documents * @throws MeilisearchException if an error occurs */ public String getRawDocuments(DocumentsQuery param) throws MeilisearchException { From 40e9e4b464166e9f6c5630339444fc6c1ddeb36a Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 5 Jan 2023 16:29:51 +0100 Subject: [PATCH 13/14] Remove result before return --- src/main/java/com/meilisearch/sdk/Documents.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index dabdc33d..ac14d64d 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -85,10 +85,8 @@ String getRawDocument(String uid, String identifier, DocumentsQuery param) * @throws MeilisearchException if the client request causes an error */ Results getDocuments(String uid, Class targetClass) throws MeilisearchException { - Results documents = - httpClient.get( - new DocumentsQuery().toQuery(uid), Results.class, targetClass); - return documents; + return httpClient.get( + new DocumentsQuery().toQuery(uid), Results.class, targetClass); } /** @@ -103,9 +101,7 @@ Results getDocuments(String uid, Class targetClass) throws Meilisearch */ Results getDocuments(String uid, DocumentsQuery param, Class targetClass) throws MeilisearchException { - Results documents = - httpClient.get(param.toQuery(uid, param), Results.class, targetClass); - return documents; + return httpClient.get(param.toQuery(uid, param), Results.class, targetClass); } /** From c9708efd6f2229f4299b0c6687a8af5b97a6e918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 16:58:45 +0100 Subject: [PATCH 14/14] Update src/main/java/com/meilisearch/sdk/Documents.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Documents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index ac14d64d..40cb8eda 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -116,7 +116,7 @@ String getRawDocuments(String uid) throws MeilisearchException { } /** - * Retrieves the document as String at the specified index + * Retrieves the document as String from the specified index * * @param uid Partial index identifier for the requested documents * @param param accepted by the documents route