Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,21 @@ reset_proximity_precision_settings_1: |-
.reset_proximity_precision()
.await
.unwrap();
facet_search_1: |-
let res = client.index("books")
.facet_search("genres")
.with_facet_query("fiction")
.with_filter("rating > 3")
.execute()
.await
.unwrap();
facet_search_3: |-
let res = client.index("books")
.facet_search("genres")
.with_facet_query("c")
.execute()
.await
.unwrap();
get_search_cutoff_1: |-
let search_cutoff_ms: String = client
.index("movies")
Expand Down
53 changes: 52 additions & 1 deletion src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,57 @@ impl<Http: HttpClient> Index<Http> {
SearchQuery::new(self)
}

/// Returns the facet stats matching a specific query in the index.
///
/// See also [`Index::facet_search`].
///
/// # Example
///
/// ```
/// # use serde::{Serialize, Deserialize};
/// # use meilisearch_sdk::{client::*, indexes::*, search::*};
/// #
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// #[derive(Serialize, Deserialize, Debug)]
/// struct Movie {
/// name: String,
/// genre: String,
/// }
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let movies = client.index("execute_query");
///
/// // add some documents
/// # 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();
/// # movies.set_filterable_attributes(["genre"]).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
///
/// let query = FacetSearchQuery::new(&movies, "genre").with_facet_query("scifi").build();
/// let res = movies.execute_facet_query(&query).await.unwrap();
///
/// assert!(res.facet_hits.len() > 0);
/// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn execute_facet_query(
&self,
body: &FacetSearchQuery<'_, Http>,
) -> Result<FacetSearchResponse, Error> {
self.client
.http_client
.request::<(), &FacetSearchQuery<Http>, FacetSearchResponse>(
&format!("{}/indexes/{}/facet-search", self.client.host, self.uid),
Method::Post { body, query: () },
200,
)
.await
}

pub fn facet_search<'a>(&'a self, facet_name: &'a str) -> FacetSearchQuery<'a, Http> {
FacetSearchQuery::new(self, facet_name)
}

/// Get one document using its unique id.
///
/// Serde is needed. Add `serde = {version="1.0", features=["derive"]}` in the dependencies section of your Cargo.toml.
Expand Down Expand Up @@ -484,7 +535,7 @@ impl<Http: HttpClient> Index<Http> {
Error::MeilisearchCommunication(MeilisearchCommunicationError {
status_code: error.status_code,
url: error.url,
message: Some(format!("{}.", MEILISEARCH_VERSION_HINT)),
message: Some(format!("{MEILISEARCH_VERSION_HINT}.")),
})
}
Error::Meilisearch(error) => Error::Meilisearch(MeilisearchError {
Expand Down
2 changes: 2 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ pub enum Action {
/// Provides access to the [delete key](https://www.meilisearch.com/docs/reference/api/keys#delete-a-key) endpoint.
#[serde(rename = "keys.delete")]
KeyDelete,
#[serde(rename = "chatCompletions")]
ChatCompletions,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down
5 changes: 1 addition & 4 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ pub fn parse_response<Output: DeserializeOwned>(
};
}

warn!(
"Expected response code {}, got {}",
expected_status_code, status_code
);
warn!("Expected response code {expected_status_code}, got {status_code}");

match from_str::<MeilisearchError>(body) {
Ok(e) => Err(Error::from(e)),
Expand Down
Loading