Skip to content

Commit 208c138

Browse files
bors[bot]sanders41
andauthored
Merge #108
108: Adding get_all_updates route r=curquiza a=sanders41 Resolves #39 The reason for renaming some of the indexes in the docs was because with them having the same names they were having side effects on each other and causing the doc tests to fail. Is this renaming acceptable, or is there a better way to handle this? The problem is related to issue #29. Co-authored-by: Paul Sanders <[email protected]>
2 parents 9fe431e + c9e3180 commit 208c138

File tree

2 files changed

+82
-4
lines changed

2 files changed

+82
-4
lines changed

.code-samples.meilisearch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ search_1: |-
6262
get_update_1: |-
6363
let status: Status = progress.get_status().await.unwrap();
6464
get_all_updates_1: |-
65-
// unavailable for now
65+
let status: Vec<ProgressStatus> = index.get_all_updates().await.unwrap();
6666
get_keys_1: |-
6767
let keys: Keys = client.get_keys().await.unwrap();
6868
get_settings_1: |-

src/indexes.rs

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a> Index<'a> {
157157
///
158158
/// # futures::executor::block_on(async move {
159159
/// let client = Client::new("http://localhost:7700", "masterKey");
160-
/// # client.delete_index("movies").await;
160+
/// # client.delete_index("movies_search").await;
161161
/// let mut movies = client.get_or_create("movies").await.unwrap();
162162
///
163163
/// // add some documents
@@ -336,7 +336,7 @@ impl<'a> Index<'a> {
336336
///
337337
/// # futures::executor::block_on(async move {
338338
/// let client = Client::new("http://localhost:7700", "masterKey");
339-
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
339+
/// let mut movie_index = client.get_or_create("movies_add_or_replace").await.unwrap();
340340
///
341341
/// movie_index.add_or_replace(&[
342342
/// Movie{
@@ -423,7 +423,7 @@ impl<'a> Index<'a> {
423423
///
424424
/// # futures::executor::block_on(async move {
425425
/// let client = Client::new("http://localhost:7700", "masterKey");
426-
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
426+
/// let mut movie_index = client.get_or_create("movies_add_or_update").await.unwrap();
427427
///
428428
/// movie_index.add_or_update(&[
429429
/// Movie{
@@ -613,6 +613,65 @@ impl<'a> Index<'a> {
613613
self.update(primary_key).await
614614
}
615615

616+
/// Get the status of all updates in a given index.
617+
///
618+
/// # Example
619+
///
620+
/// ```
621+
/// # use serde::{Serialize, Deserialize};
622+
/// # use std::thread::sleep;
623+
/// # use std::time::Duration;
624+
/// # use meilisearch_sdk::{client::*, document, indexes::*};
625+
/// #
626+
/// # #[derive(Debug, Serialize, Deserialize, PartialEq)]
627+
/// # struct Document {
628+
/// # id: usize,
629+
/// # value: String,
630+
/// # kind: String,
631+
/// # }
632+
/// #
633+
/// # impl document::Document for Document {
634+
/// # type UIDType = usize;
635+
/// #
636+
/// # fn get_uid(&self) -> &Self::UIDType {
637+
/// # &self.id
638+
/// # }
639+
/// # }
640+
/// #
641+
/// # futures::executor::block_on(async move {
642+
/// let client = Client::new("http://localhost:7700", "masterKey");
643+
/// let movies = client.get_or_create("movies_get_all_updates").await.unwrap();
644+
///
645+
/// # movies.add_documents(&[
646+
/// # Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() },
647+
/// # Document { id: 1, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string() },
648+
/// # ], None).await.unwrap();
649+
/// # sleep(Duration::from_secs(1));
650+
///
651+
/// # movies.add_documents(&[
652+
/// # Document { id: 0, kind: "title".into(), value: "Harry Potter and the Chamber of Secrets".to_string() },
653+
/// # Document { id: 1, kind: "title".into(), value: "Harry Potter and the Prisoner of Azkaban".to_string() },
654+
/// # ], None).await.unwrap();
655+
/// # sleep(Duration::from_secs(1));
656+
///
657+
/// let status = movies.get_all_updates().await.unwrap();
658+
/// assert_eq!(status.len(), 2);
659+
/// # client.delete_index("movies_get_all_updates").await.unwrap();
660+
/// # });
661+
/// ```
662+
pub async fn get_all_updates(&self) -> Result<Vec<ProcessedStatus>, Error> {
663+
request::<(), Vec<ProcessedStatus>>(
664+
&format!(
665+
"{}/indexes/{}/updates",
666+
self.client.host, self.uid
667+
),
668+
self.client.apikey,
669+
Method::Get,
670+
200,
671+
)
672+
.await
673+
}
674+
616675
/// Get stats of an index.
617676
///
618677
/// # Example
@@ -644,3 +703,22 @@ pub struct IndexStats {
644703
pub is_indexing: bool,
645704
pub fields_distribution: HashMap<String, usize>,
646705
}
706+
707+
#[cfg(test)]
708+
mod tests {
709+
use crate::{client::*};
710+
use futures_await_test::async_test;
711+
712+
#[async_test]
713+
async fn test_get_all_updates_no_docs() {
714+
let client = Client::new("http://localhost:7700", "masterKey");
715+
let uid = "test_get_all_updates_no_docs";
716+
717+
let index = client.create_index(uid, None).await.unwrap();
718+
let status = index.get_all_updates().await.unwrap();
719+
720+
assert_eq!(status.len(), 0);
721+
722+
client.delete_index(uid).await.unwrap();
723+
}
724+
}

0 commit comments

Comments
 (0)