@@ -279,6 +279,57 @@ impl<Http: HttpClient> Index<Http> {
279279 SearchQuery :: new ( self )
280280 }
281281
282+ /// Returns the facet stats matching a specific query in the index.
283+ ///
284+ /// See also [`Index::facet_search`].
285+ ///
286+ /// # Example
287+ ///
288+ /// ```
289+ /// # use serde::{Serialize, Deserialize};
290+ /// # use meilisearch_sdk::{client::*, indexes::*, search::*};
291+ /// #
292+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
293+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
294+ /// #
295+ /// #[derive(Serialize, Deserialize, Debug)]
296+ /// struct Movie {
297+ /// name: String,
298+ /// genre: String,
299+ /// }
300+ /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
301+ /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
302+ /// let movies = client.index("execute_query2");
303+ ///
304+ /// // add some documents
305+ /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), genre:String::from("scifi")},Movie{name:String::from("Inception"), genre:String::from("drama")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
306+ /// # movies.set_filterable_attributes(["genre"]).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
307+ ///
308+ /// let query = FacetSearchQuery::new(&movies, "genre").with_facet_query("scifi").build();
309+ /// let res = movies.execute_facet_query(&query).await.unwrap();
310+ ///
311+ /// assert!(res.facet_hits.len() > 0);
312+ /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
313+ /// # });
314+ /// ```
315+ pub async fn execute_facet_query (
316+ & self ,
317+ body : & FacetSearchQuery < ' _ , Http > ,
318+ ) -> Result < FacetSearchResponse , Error > {
319+ self . client
320+ . http_client
321+ . request :: < ( ) , & FacetSearchQuery < Http > , FacetSearchResponse > (
322+ & format ! ( "{}/indexes/{}/facet-search" , self . client. host, self . uid) ,
323+ Method :: Post { body, query : ( ) } ,
324+ 200 ,
325+ )
326+ . await
327+ }
328+
329+ pub fn facet_search < ' a > ( & ' a self , facet_name : & ' a str ) -> FacetSearchQuery < ' a , Http > {
330+ FacetSearchQuery :: new ( self , facet_name)
331+ }
332+
282333 /// Get one document using its unique id.
283334 ///
284335 /// Serde is needed. Add `serde = {version="1.0", features=["derive"]}` in the dependencies section of your Cargo.toml.
@@ -484,7 +535,7 @@ impl<Http: HttpClient> Index<Http> {
484535 Error :: MeilisearchCommunication ( MeilisearchCommunicationError {
485536 status_code : error. status_code ,
486537 url : error. url ,
487- message : Some ( format ! ( "{}." , MEILISEARCH_VERSION_HINT ) ) ,
538+ message : Some ( format ! ( "{MEILISEARCH_VERSION_HINT }." ) ) ,
488539 } )
489540 }
490541 Error :: Meilisearch ( error) => Error :: Meilisearch ( MeilisearchError {
@@ -668,7 +719,7 @@ impl<Http: HttpClient> Index<Http> {
668719 self . add_or_replace ( documents, primary_key) . await
669720 }
670721
671- /// Add a raw ndjson payload and update them if they already.
722+ /// Add a raw ndjson payload and update them if they already exist .
672723 ///
673724 /// It configures the correct content type for ndjson data.
674725 ///
@@ -760,7 +811,7 @@ impl<Http: HttpClient> Index<Http> {
760811 . await
761812 }
762813
763- /// Add a raw csv payload and update them if they already.
814+ /// Add a raw csv payload and update them if they already exist .
764815 ///
765816 /// It configures the correct content type for csv data.
766817 ///
@@ -850,7 +901,7 @@ impl<Http: HttpClient> Index<Http> {
850901 . await
851902 }
852903
853- /// Add a list of documents and update them if they already.
904+ /// Add a list of documents and update them if they already exist .
854905 ///
855906 /// If you send an already existing document (same id) the old document will be only partially updated according to the fields of the new document.
856907 /// Thus, any fields not present in the new document are kept and remained unchanged.
@@ -1795,8 +1846,25 @@ impl<'a, Http: HttpClient> AsRef<IndexUpdater<'a, Http>> for IndexUpdater<'a, Ht
17951846#[ derive( Debug , Clone , Deserialize ) ]
17961847#[ serde( rename_all = "camelCase" ) ]
17971848pub struct IndexStats {
1849+ /// Total number of documents in an index
17981850 pub number_of_documents : usize ,
1851+
1852+ /// Total number of documents with at least one embedding
1853+ pub number_of_embedded_documents : usize ,
1854+
1855+ /// Total number of embeddings in an index
1856+ pub number_of_embeddings : usize ,
1857+
1858+ /// Storage space claimed by all documents in the index in bytes
1859+ pub raw_document_db_size : usize ,
1860+
1861+ /// Total size of the documents stored in an index divided by the number of documents in that same index
1862+ pub avg_document_size : usize ,
1863+
1864+ /// If `true`, the index is still processing documents and attempts to search will yield impredictable results
17991865 pub is_indexing : bool ,
1866+
1867+ /// Shows every field in the index along with the total number of documents containing that field in said index
18001868 pub field_distribution : HashMap < String , usize > ,
18011869}
18021870
0 commit comments