Skip to content

Commit 4c11a52

Browse files
authored
Merge branch 'hybrid' into vector-search-embedder
2 parents b04d320 + 6de4acf commit 4c11a52

File tree

6 files changed

+540
-19
lines changed

6 files changed

+540
-19
lines changed

.code-samples.meilisearch.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Every example written here will be automatically fetched by
33
# the documentation on build
44
# You can read more on https://github.com/meilisearch/documentation/tree/main/learn
5+
# See the original at https://github.com/meilisearch/documentation/blob/main/.code-samples.meilisearch.yaml
56
---
67
synonyms_guide_1: |-
78
let mut synonyms = std::collections::HashMap::new();
@@ -581,8 +582,12 @@ get_faceting_settings_1: |-
581582
.await
582583
.unwrap();
583584
update_faceting_settings_1: |-
585+
let mut facet_sort_setting = BTreeMap::new();
586+
facet_sort_setting.insert(String::from("*"), FacetSortValue::Alpha);
587+
facet_sort_setting.insert(String::from("genres"), FacetSortValue::Count);
584588
let mut faceting = FacetingSettings {
585589
max_values_per_facet: 2,
590+
sort_facet_values_by: Some(facet_sort_setting),
586591
};
587592
588593
let task: TaskInfo = client
@@ -1265,8 +1270,11 @@ getting_started_sorting: |-
12651270
.await
12661271
.unwrap();
12671272
getting_started_faceting: |-
1273+
let mut facet_sort_setting = BTreeMap::new();
1274+
facet_sort_setting.insert("*".to_string(), FacetSortValue::Count);
12681275
let mut faceting = FacetingSettings {
12691276
max_values_per_facet: 2,
1277+
sort_facet_values_by: Some(facet_sort_setting),
12701278
};
12711279
12721280
let task: TaskInfo = client
@@ -1663,6 +1671,33 @@ reset_proximity_precision_settings_1: |-
16631671
.reset_proximity_precision()
16641672
.await
16651673
.unwrap();
1674+
facet_search_1: |-
1675+
let res = client.index("books")
1676+
.facet_search("genres")
1677+
.with_facet_query("fiction")
1678+
.with_filter("rating > 3")
1679+
.execute()
1680+
.await
1681+
.unwrap();
1682+
facet_search_2: |-
1683+
let mut facet_sort_setting = BTreeMap::new();
1684+
facet_sort_setting.insert("genres".to_string(), FacetSortValue::Count);
1685+
let faceting = FacetingSettings {
1686+
max_values_per_facet: 100,
1687+
sort_facet_values_by: Some(facet_sort_setting),
1688+
};
1689+
1690+
let res = client.index("books")
1691+
.set_faceting(&faceting)
1692+
.await
1693+
.unwrap();
1694+
facet_search_3: |-
1695+
let res = client.index("books")
1696+
.facet_search("genres")
1697+
.with_facet_query("c")
1698+
.execute()
1699+
.await
1700+
.unwrap();
16661701
get_search_cutoff_1: |-
16671702
let search_cutoff_ms: String = client
16681703
.index("movies")

src/indexes.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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_query");
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 {

src/key.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ pub enum Action {
713713
/// Provides access to the [delete key](https://www.meilisearch.com/docs/reference/api/keys#delete-a-key) endpoint.
714714
#[serde(rename = "keys.delete")]
715715
KeyDelete,
716+
#[serde(rename = "chatCompletions")]
717+
ChatCompletions,
716718
}
717719

718720
#[derive(Debug, Clone, Deserialize)]

src/request.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ pub fn parse_response<Output: DeserializeOwned>(
122122
};
123123
}
124124

125-
warn!(
126-
"Expected response code {}, got {}",
127-
expected_status_code, status_code
128-
);
125+
warn!("Expected response code {expected_status_code}, got {status_code}");
129126

130127
match from_str::<MeilisearchError>(body) {
131128
Ok(e) => Err(Error::from(e)),

0 commit comments

Comments
 (0)