Skip to content

Commit

Permalink
Merge branch 'bump-meilisearch-v1.1.0' of github.com:meilisearch/meil…
Browse files Browse the repository at this point in the history
…isearch-rust into bump-meilisearch-v1.1.0
  • Loading branch information
bidoubiwa committed Mar 29, 2023
2 parents db82c10 + eaa535a commit 9783557
Showing 1 changed file with 53 additions and 17 deletions.
70 changes: 53 additions & 17 deletions src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ impl Index {
/// { "id": 2, "body": "catto" }"#.as_bytes(),
/// "application/x-ndjson",
/// Some("id"),
/// None
/// ).await.unwrap();
/// // Meilisearch may take some time to execute the request so we are going to wait till it's completed
/// client.wait_for_task(task, None, None).await.unwrap();
Expand All @@ -604,15 +605,16 @@ impl Index {
payload: T,
content_type: &str,
primary_key: Option<&str>,
csv_delimiter: Option<&str>,
) -> Result<TaskInfo, Error> {
let url = if let Some(primary_key) = primary_key {
format!(
"{}/indexes/{}/documents?primaryKey={}",
self.client.host, self.uid, primary_key
)
} else {
format!("{}/indexes/{}/documents", self.client.host, self.uid)
};
let mut url = format!("{}/indexes/{}/documents?", self.client.host, self.uid);
if let Some(primary_key) = primary_key {
url = format!("{}primaryKey={}&", url, primary_key)
}

if let Some(csv_delimiter) = csv_delimiter {
url = format!("{}csvDelimiter={}", url, csv_delimiter)
}
stream_request::<(), T, TaskInfo>(
&url,
&self.client.api_key,
Expand Down Expand Up @@ -736,13 +738,14 @@ impl Index {
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// # futures::executor::block_on(async move {
/// let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
/// let movie_index = client.index("add_or_replace_unchecked_payload");
/// let movie_index = client.index("add_or_update_unchecked_payload");
///
/// let task = movie_index.add_or_update_unchecked_payload(
/// r#"{ "id": 1, "body": "doggo" }
/// { "id": 2, "body": "catto" }"#.as_bytes(),
/// "application/x-ndjson",
/// Some("id"),
/// None
/// ).await.unwrap();
/// // Meilisearch may take some time to execute the request so we are going to wait till it's completed
/// client.wait_for_task(task, None, None).await.unwrap();
Expand All @@ -760,15 +763,18 @@ impl Index {
payload: T,
content_type: &str,
primary_key: Option<&str>,
csv_delimiter: Option<&str>,
) -> Result<TaskInfo, Error> {
let url = if let Some(primary_key) = primary_key {
format!(
"{}/indexes/{}/documents?primaryKey={}",
self.client.host, self.uid, primary_key
)
} else {
format!("{}/indexes/{}/documents", self.client.host, self.uid)
};
let mut url = format!("{}/indexes/{}/documents?", self.client.host, self.uid);

if let Some(primary_key) = primary_key {
url = format!("{}primaryKey={}&", url, primary_key)
}

if let Some(csv_delimiter) = csv_delimiter {
url = format!("{}csvDelimiter={}", url, csv_delimiter)
}

stream_request::<(), T, TaskInfo>(
&url,
&self.client.api_key,
Expand Down Expand Up @@ -1779,6 +1785,36 @@ mod tests {
assert_eq!(res.offset, 2);
}

#[meilisearch_test]
async fn test_add_documents_in_csv_with_custom_delimiter(
client: Client,
index: Index,
) -> Result<(), Error> {
#[derive(Serialize, Deserialize, Debug)]
struct Movie {
name: String,
description: String,
}

let task = index
.add_or_replace_unchecked_payload(
r#"name,description
wonderwoman,She's incredible"#
.as_bytes(),
"text/csv",
Some("name"),
Some(","),
)
.await
.unwrap();

let task = client.wait_for_task(task, None, None).await.unwrap();
let movies = index.get_documents::<Movie>().await.unwrap();

assert_eq!(movies.results.len(), 1);
Ok(())
}

#[meilisearch_test]
async fn test_get_one_task(client: Client, index: Index) -> Result<(), Error> {
let task = index
Expand Down

0 comments on commit 9783557

Please sign in to comment.