Skip to content

Commit

Permalink
Merge #726
Browse files Browse the repository at this point in the history
726: Custom csv delimiter r=curquiza a=jennweir

# Pull Request

## Related issue
Addresses #590 

## What does this PR do?
- Includes csvDelimiter parameter in the addDocuments method
- Includes csvDelimiter parameter in the updateDocuments method
### Issue #590 has two subtasks as listed below:
- [x] Add the new argument to the csv document handler methods
- [ ] Add tests
- Tests are not included because there are some clarifications that we require to verify if the issue is already partially/completely implemented. After adding the csvDelimiter to each method, we researched adding a custom csv delimiter in Java and found no built-in support. Would this be best completed by utilizing an external library like OpenCSV? 
- This PR addresses the function parameter additions to support a custom csvDelimiter if necessary but does not adequately test the functionality of these additions. 
- It is unclear from the issue if this is already implemented, this would address the first subtask for #590 if the issue has not been implemented yet.

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Anna <[email protected]>
Co-authored-by: Jennifer Weir <[email protected]>
Co-authored-by: Jennifer Weir <[email protected]>
  • Loading branch information
4 people authored May 15, 2024
2 parents 5141458 + ad7e979 commit e6a7c16
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
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 @@ -154,15 +154,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 @@ -175,12 +179,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

0 comments on commit e6a7c16

Please sign in to comment.