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

Custom csv delimiter #726

Merged
merged 9 commits into from
May 15, 2024
11 changes: 9 additions & 2 deletions src/main/java/com/meilisearch/sdk/Documents.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@ 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
*/
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);
}

Expand All @@ -164,12 +168,15 @@ TaskInfo addDocuments(String uid, String document, String primaryKey)
* @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);
}

Expand Down
48 changes: 42 additions & 6 deletions src/main/java/com/meilisearch/sdk/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public String getRawDocuments(DocumentsQuery param) throws MeilisearchException
* specification</a>
*/
public TaskInfo addDocuments(String document) throws MeilisearchException {
return this.documents.addDocuments(this.uid, document, null);
return this.documents.addDocuments(this.uid, document, null, null);
}

/**
Expand All @@ -181,7 +181,24 @@ public TaskInfo addDocuments(String document) throws MeilisearchException {
* specification</a>
*/
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 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
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/documents#add-or-replace-documents">API
* specification</a>
*/
public TaskInfo addDocuments(String document, String primaryKey, String csvDelimiter)
throws MeilisearchException {
return this.documents.addDocuments(this.uid, document, primaryKey, csvDelimiter);
}

/**
Expand Down Expand Up @@ -211,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));
this.documents.addDocuments(
this.uid, jsonSubArray.toString(), primaryKey, null));
}
return arrayResponses.toArray(new TaskInfo[arrayResponses.size()]);
}
Expand Down Expand Up @@ -241,7 +259,7 @@ public TaskInfo[] addDocumentsInBatches(String document) throws MeilisearchExcep
* specification</a>
*/
public TaskInfo updateDocuments(String document) throws MeilisearchException {
return this.documents.updateDocuments(this.uid, document, null);
return this.documents.updateDocuments(this.uid, document, null, null);
}

/**
Expand All @@ -257,7 +275,24 @@ 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
* @param csvDelimiter Custom delimiter to use for the document being added
* @return TaskInfo Meilisearch API response
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/documents#add-or-replace-documents">API
* specification</a>
*/
public TaskInfo updateDocuments(String document, String primaryKey, String csvDelimiter)
throws MeilisearchException {
return this.documents.updateDocuments(this.uid, document, primaryKey, csvDelimiter);
}

/**
Expand Down Expand Up @@ -287,7 +322,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()]);
}
Expand Down
Loading