From 55cf8fb3a34bff8ecf91c129ef1e20f87eba2136 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 11 Apr 2024 17:52:04 -0400 Subject: [PATCH 1/8] added csvDelimiter not null check to addDocuments function in Documents.java --- src/main/java/com/meilisearch/sdk/Documents.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index 9352ae77..3cb717ad 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -146,12 +146,15 @@ String getRawDocuments(String uid, DocumentsQuery param) throws MeilisearchExcep * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ - TaskInfo addDocuments(String uid, String document, String primaryKey) + TaskInfo addDocuments(String uid, String document, String primaryKey, String csvDelimiter) throws MeilisearchException { URLBuilder urlb = documentPath(uid); if (primaryKey != null) { urlb.addParameter("primaryKey", primaryKey); } + if (csvDelimiter != null) { + urlb.addParameter("csvDelimiter", csvDelimiter); + } return httpClient.post(urlb.getURL(), document, TaskInfo.class); } From c6351249dcad7190d92533322696d26212e31c37 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 11 Apr 2024 18:01:35 -0400 Subject: [PATCH 2/8] added csvDelimiter parameter to addDocuments function --- src/main/java/com/meilisearch/sdk/Documents.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index 3cb717ad..f16c2e20 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -143,6 +143,7 @@ String getRawDocuments(String uid, DocumentsQuery param) throws MeilisearchExcep * @param uid Partial index identifier for the document * @param document String containing the document to add * @param primaryKey PrimaryKey of the document + * @param csvDelimiter CSV delimiter of the document * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ From da197fe59aee52f59300373bb9c4ac3bc111901a Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 11 Apr 2024 18:16:09 -0400 Subject: [PATCH 3/8] edited addDocuments function calls in the Index.java file to include the csvDelimiter parameter --- src/main/java/com/meilisearch/sdk/Index.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index 2a81862c..91a4c893 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -166,7 +166,7 @@ public String getRawDocuments(DocumentsQuery param) throws MeilisearchException * specification */ public TaskInfo addDocuments(String document) throws MeilisearchException { - return this.documents.addDocuments(this.uid, document, null); + return this.documents.addDocuments(this.uid, document, null, null); } /** @@ -181,7 +181,23 @@ public TaskInfo addDocuments(String document) throws MeilisearchException { * specification */ public TaskInfo addDocuments(String document, String primaryKey) throws MeilisearchException { - return this.documents.addDocuments(this.uid, document, primaryKey); + return this.documents.addDocuments(this.uid, document, primaryKey, null); + } + + /** + * Adds/Replaces documents in the index + * + * @param document Document to add in JSON string format + * @param primaryKey PrimaryKey of the document to add + * @param csvDelimiter Custom delimiter to use for the document being added + * @return TaskInfo Meilisearch API response + * @throws MeilisearchException if an error occurs + * @see API + * specification + */ + public TaskInfo addDocuments(String document, String primaryKey, String csvDelimiter) throws MeilisearchException { + return this.documents.addDocuments(this.uid, document, primaryKey, csvDelimiter); } /** From cb1cec2da33a4f41641de14acdad26efc6f9124a Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 11 Apr 2024 18:34:40 -0400 Subject: [PATCH 4/8] edited addDocuments route to include csvDelimiter for documents to add in CSV format --- 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 91a4c893..f7cfab14 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -187,7 +187,7 @@ public TaskInfo addDocuments(String document, String primaryKey) throws Meilisea /** * Adds/Replaces documents in the index * - * @param document Document to add in JSON string format + * @param document Document to add in CSV string format * @param primaryKey PrimaryKey of the document to add * @param csvDelimiter Custom delimiter to use for the document being added * @return TaskInfo Meilisearch API response From 0b3caa3927f8a3447c72a23bd719b4623062d829 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 11 Apr 2024 18:43:37 -0400 Subject: [PATCH 5/8] added null field to the addDocuments batches call in Index --- 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 f7cfab14..b1ff7c86 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -227,7 +227,7 @@ public TaskInfo[] addDocumentsInBatches(String document, Integer batchSize, Stri jsonSubArray.put(j, jsonDocumentsArray.get(i + j)); } arrayResponses.add( - this.documents.addDocuments(this.uid, jsonSubArray.toString(), primaryKey)); + this.documents.addDocuments(this.uid, jsonSubArray.toString(), primaryKey, null)); } return arrayResponses.toArray(new TaskInfo[arrayResponses.size()]); } From eea5dcf4822dada92e02cfb7b362a475303c7818 Mon Sep 17 00:00:00 2001 From: Jennifer Weir Date: Tue, 16 Apr 2024 11:56:49 -0400 Subject: [PATCH 6/8] included a test for the add documents custom csv delimiter --- src/main/java/com/meilisearch/sdk/Index.java | 6 ++- .../integration/DocumentsTest.java | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index b1ff7c86..01bd2f2e 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -196,7 +196,8 @@ public TaskInfo addDocuments(String document, String primaryKey) throws Meilisea * href="https://www.meilisearch.com/docs/reference/api/documents#add-or-replace-documents">API * specification */ - public TaskInfo addDocuments(String document, String primaryKey, String csvDelimiter) throws MeilisearchException { + public TaskInfo addDocuments(String document, String primaryKey, String csvDelimiter) + throws MeilisearchException { return this.documents.addDocuments(this.uid, document, primaryKey, csvDelimiter); } @@ -227,7 +228,8 @@ public TaskInfo[] addDocumentsInBatches(String document, Integer batchSize, Stri jsonSubArray.put(j, jsonDocumentsArray.get(i + j)); } arrayResponses.add( - this.documents.addDocuments(this.uid, jsonSubArray.toString(), primaryKey, null)); + this.documents.addDocuments( + this.uid, jsonSubArray.toString(), primaryKey, null)); } return arrayResponses.toArray(new TaskInfo[arrayResponses.size()]); } diff --git a/src/test/java/com/meilisearch/integration/DocumentsTest.java b/src/test/java/com/meilisearch/integration/DocumentsTest.java index 6181036d..b7cdbc8d 100644 --- a/src/test/java/com/meilisearch/integration/DocumentsTest.java +++ b/src/test/java/com/meilisearch/integration/DocumentsTest.java @@ -73,6 +73,44 @@ public void testAddDocumentsSingle() throws Exception { assertThat(movies[0].getGenres()[1], is(equalTo("Drama"))); } + /** Test Add single document with Custom csv delimiter */ + @Test + public void testAddDocumentsSingleCsv() throws Exception { + + String indexUid = "AddDocumentsSingleCsv"; + Index index = client.index(indexUid); + + TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); + String singleDocument = this.gson.toJson(testData.getData().get(0)); + + // Create the custom csv delimiter here + String customDelimiter = ";"; + String csvData = "[" + singleDocument.replaceAll(",", customDelimiter) + "]"; + + // TODO: what should the PK be? + TaskInfo task = index.addDocuments(singleDocument, "", customDelimiter); + + index.waitForTask(task.getTaskUid()); + Results result = index.getDocuments(Movie.class); + Movie[] movies = result.getResults(); + + String expectedOverview = + "The near future, a time when both hope and hardships drive humanity to look to the stars and beyond. While a mysterious phenomenon menaces to destroy life on planet Earth, astronaut Roy McBride undertakes a mission across the immensity of space and its many perils to uncover the truth about a lost expedition that decades before boldly faced emptiness and silence in search of the unknown."; + assertThat(movies, is(arrayWithSize(1))); + assertThat(movies[0].getId(), is(equalTo("419704"))); + assertThat(movies[0].getTitle(), is(equalTo("Ad Astra"))); + assertThat( + movies[0].getPoster(), + is(equalTo("https://image.tmdb.org/t/p/original/xBHvZcjRiWyobQ9kxBhO6B2dtRI.jpg"))); + assertThat(movies[0].getOverview(), is(equalTo(expectedOverview))); + assertThat(movies[0].getRelease_date(), is(equalTo("2019-09-17"))); + assertThat(movies[0].getLanguage(), is(equalTo("en"))); + assertThat(movies[0].getGenres(), is(notNullValue())); + assertThat(movies[0].getGenres(), is(arrayWithSize(2))); + assertThat(movies[0].getGenres()[0], is(equalTo("Science Fiction"))); + assertThat(movies[0].getGenres()[1], is(equalTo("Drama"))); + } + /** Test add Documents with primaryKey */ @Test public void testAddDocumentsWithSuppliedPrimaryKey() throws Exception { From bcd3e8a0cd272dd0f3270df3d76de83d24e90d12 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 22 Apr 2024 13:56:06 -0400 Subject: [PATCH 7/8] removed test and added csv parameter in updateDocuments in Index.java and Documents.java --- .../java/com/meilisearch/sdk/Documents.java | 5 ++- src/main/java/com/meilisearch/sdk/Index.java | 23 ++++++++++-- .../integration/DocumentsTest.java | 37 ------------------- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index f16c2e20..da52a437 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -168,12 +168,15 @@ TaskInfo addDocuments(String uid, String document, String primaryKey, String csv * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ - TaskInfo updateDocuments(String uid, String document, String primaryKey) + TaskInfo updateDocuments(String uid, String document, String primaryKey, String csvDelimiter) throws MeilisearchException { URLBuilder urlb = documentPath(uid); if (primaryKey != null) { urlb.addParameter("primaryKey", primaryKey); } + if (csvDelimiter != null) { + urlb.addParameter("csvDelimiter", csvDelimiter); + } return httpClient.put(urlb.getURL(), document, TaskInfo.class); } diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index 01bd2f2e..7a908609 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -259,7 +259,7 @@ public TaskInfo[] addDocumentsInBatches(String document) throws MeilisearchExcep * specification */ public TaskInfo updateDocuments(String document) throws MeilisearchException { - return this.documents.updateDocuments(this.uid, document, null); + return this.documents.updateDocuments(this.uid, document, null, null); } /** @@ -275,7 +275,23 @@ public TaskInfo updateDocuments(String document) throws MeilisearchException { */ public TaskInfo updateDocuments(String document, String primaryKey) throws MeilisearchException { - return this.documents.updateDocuments(this.uid, document, primaryKey); + return this.documents.updateDocuments(this.uid, document, primaryKey, null); + } + + /** + * Updates documents in the index + * + * @param document Document to update in CSV string format + * @param primaryKey PrimaryKey of the document + * @return TaskInfo Meilisearch API response + * @throws MeilisearchException if an error occurs + * @see API + * specification + */ + public TaskInfo updateDocuments(String document, String primaryKey, String csvDelimiter) + throws MeilisearchException { + return this.documents.updateDocuments(this.uid, document, primaryKey, csvDelimiter); } /** @@ -305,7 +321,8 @@ public TaskInfo[] updateDocumentsInBatches( jsonSubArray.put(j, jsonDocumentsArray.get(i + j)); } arrayResponses.add( - this.documents.updateDocuments(this.uid, jsonSubArray.toString(), primaryKey)); + this.documents.updateDocuments( + this.uid, jsonSubArray.toString(), primaryKey, null)); } return arrayResponses.toArray(new TaskInfo[arrayResponses.size()]); } diff --git a/src/test/java/com/meilisearch/integration/DocumentsTest.java b/src/test/java/com/meilisearch/integration/DocumentsTest.java index b7cdbc8d..73213370 100644 --- a/src/test/java/com/meilisearch/integration/DocumentsTest.java +++ b/src/test/java/com/meilisearch/integration/DocumentsTest.java @@ -73,43 +73,6 @@ public void testAddDocumentsSingle() throws Exception { assertThat(movies[0].getGenres()[1], is(equalTo("Drama"))); } - /** Test Add single document with Custom csv delimiter */ - @Test - public void testAddDocumentsSingleCsv() throws Exception { - - String indexUid = "AddDocumentsSingleCsv"; - Index index = client.index(indexUid); - - TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - String singleDocument = this.gson.toJson(testData.getData().get(0)); - - // Create the custom csv delimiter here - String customDelimiter = ";"; - String csvData = "[" + singleDocument.replaceAll(",", customDelimiter) + "]"; - - // TODO: what should the PK be? - TaskInfo task = index.addDocuments(singleDocument, "", customDelimiter); - - index.waitForTask(task.getTaskUid()); - Results result = index.getDocuments(Movie.class); - Movie[] movies = result.getResults(); - - String expectedOverview = - "The near future, a time when both hope and hardships drive humanity to look to the stars and beyond. While a mysterious phenomenon menaces to destroy life on planet Earth, astronaut Roy McBride undertakes a mission across the immensity of space and its many perils to uncover the truth about a lost expedition that decades before boldly faced emptiness and silence in search of the unknown."; - assertThat(movies, is(arrayWithSize(1))); - assertThat(movies[0].getId(), is(equalTo("419704"))); - assertThat(movies[0].getTitle(), is(equalTo("Ad Astra"))); - assertThat( - movies[0].getPoster(), - is(equalTo("https://image.tmdb.org/t/p/original/xBHvZcjRiWyobQ9kxBhO6B2dtRI.jpg"))); - assertThat(movies[0].getOverview(), is(equalTo(expectedOverview))); - assertThat(movies[0].getRelease_date(), is(equalTo("2019-09-17"))); - assertThat(movies[0].getLanguage(), is(equalTo("en"))); - assertThat(movies[0].getGenres(), is(notNullValue())); - assertThat(movies[0].getGenres(), is(arrayWithSize(2))); - assertThat(movies[0].getGenres()[0], is(equalTo("Science Fiction"))); - assertThat(movies[0].getGenres()[1], is(equalTo("Drama"))); - } /** Test add Documents with primaryKey */ @Test From ad7e979715ec929af2c934cce1c637eb208ce7da Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 22 Apr 2024 14:13:33 -0400 Subject: [PATCH 8/8] updated comment to include csvDelimiter for updateDocuments in Index.java --- src/main/java/com/meilisearch/sdk/Index.java | 1 + src/test/java/com/meilisearch/integration/DocumentsTest.java | 1 - 2 files 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 7a908609..3751c1e2 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -283,6 +283,7 @@ public TaskInfo updateDocuments(String document, String primaryKey) * * @param document Document to update in CSV string format * @param primaryKey PrimaryKey of the document + * @param csvDelimiter Custom delimiter to use for the document being added * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs * @see