@@ -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