diff --git a/meilisearch-types/src/document_formats.rs b/meilisearch-types/src/document_formats.rs index 206cfdcc0..0b5f96ec0 100644 --- a/meilisearch-types/src/document_formats.rs +++ b/meilisearch-types/src/document_formats.rs @@ -19,7 +19,7 @@ type Result = std::result::Result; pub enum PayloadType { Ndjson, Json, - Csv(u8), + Csv { delimiter: u8 }, } impl fmt::Display for PayloadType { @@ -27,7 +27,7 @@ impl fmt::Display for PayloadType { match self { PayloadType::Ndjson => f.write_str("ndjson"), PayloadType::Json => f.write_str("json"), - PayloadType::Csv(_) => f.write_str("csv"), + PayloadType::Csv { .. } => f.write_str("csv"), } } } @@ -109,7 +109,7 @@ pub fn read_csv(file: &File, writer: impl Write + Seek, delimiter: u8) -> Result let mut builder = DocumentsBatchBuilder::new(writer); let mmap = unsafe { MmapOptions::new().map(file)? }; let csv = csv::ReaderBuilder::new().delimiter(delimiter).from_reader(mmap.as_ref()); - builder.append_csv(csv).map_err(|e| (PayloadType::Csv(delimiter), e))?; + builder.append_csv(csv).map_err(|e| (PayloadType::Csv { delimiter }, e))?; let count = builder.documents_count(); let _ = builder.into_inner().map_err(DocumentFormatError::Io)?; diff --git a/meilisearch/src/routes/indexes/documents.rs b/meilisearch/src/routes/indexes/documents.rs index 529635704..0c649ea5d 100644 --- a/meilisearch/src/routes/indexes/documents.rs +++ b/meilisearch/src/routes/indexes/documents.rs @@ -256,8 +256,8 @@ async fn document_addition( ) { (Some(("application", "json")), None) => PayloadType::Json, (Some(("application", "x-ndjson")), None) => PayloadType::Ndjson, - (Some(("text", "csv")), None) => PayloadType::Csv(b','), - (Some(("text", "csv")), Some(delimiter)) => PayloadType::Csv(delimiter), + (Some(("text", "csv")), None) => PayloadType::Csv { delimiter: b',' }, + (Some(("text", "csv")), Some(delimiter)) => PayloadType::Csv { delimiter }, (Some(("application", "json")), Some(_)) => { return Err(MeilisearchHttpError::CsvDelimiterWithWrongContentType(String::from( @@ -320,7 +320,9 @@ async fn document_addition( let documents_count = tokio::task::spawn_blocking(move || { let documents_count = match format { PayloadType::Json => read_json(&read_file, update_file.as_file_mut())?, - PayloadType::Csv(delim) => read_csv(&read_file, update_file.as_file_mut(), delim)?, + PayloadType::Csv { delimiter } => { + read_csv(&read_file, update_file.as_file_mut(), delimiter)? + } PayloadType::Ndjson => read_ndjson(&read_file, update_file.as_file_mut())?, }; // we NEED to persist the file here because we moved the `udpate_file` in another task.