diff --git a/src/search.rs b/src/search.rs index abc4befc..dcb4d368 100644 --- a/src/search.rs +++ b/src/search.rs @@ -47,6 +47,14 @@ pub enum MatchingStrategies { FREQUENCY, } +/// Hybrid search options. +#[derive(Debug, Clone, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct HybridSearch { + pub semantic_ratio: f64, + pub embedder: String, +} + /// A single result. /// /// Contains the complete object, optionally the formatted object, and optionally an object that contains information about the matches. @@ -347,14 +355,22 @@ pub struct SearchQuery<'a, Http: HttpClient> { #[serde(skip_serializing_if = "Option::is_none")] pub matching_strategy: Option, - ///Defines one attribute in the filterableAttributes list as a distinct attribute. + /// Defines one attribute in the filterableAttributes list as a distinct attribute. #[serde(skip_serializing_if = "Option::is_none")] pub distinct: Option<&'a str>, - ///Excludes results below the specified ranking score. + /// Excludes results below the specified ranking score. #[serde(skip_serializing_if = "Option::is_none")] pub ranking_score_threshold: Option, + /// Defines hybrid search options. + #[serde(skip_serializing_if = "Option::is_none")] + pub hybrid: Option, + + /// Defines a custom embedding vector. + #[serde(skip_serializing_if = "Option::is_none")] + pub vector: Option>, + /// Defines the language of the search query. #[serde(skip_serializing_if = "Option::is_none")] pub locales: Option<&'a [&'a str]>, @@ -392,6 +408,8 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> { index_uid: None, distinct: None, ranking_score_threshold: None, + hybrid: None, + vector: None, locales: None, } } @@ -596,6 +614,20 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> { self.ranking_score_threshold = Some(ranking_score_threshold); self } + pub fn with_hybrid_search<'b>( + &'b mut self, + hybrid: HybridSearch, + ) -> &'b mut SearchQuery<'a, Http> { + self.hybrid = Some(hybrid); + self + } + pub fn with_custom_embedding_vector<'b>( + &'b mut self, + vector: Vec, + ) -> &'b mut SearchQuery<'a, Http> { + self.vector = Some(vector); + self + } pub fn with_locales<'b>(&'b mut self, locales: &'a [&'a str]) -> &'b mut SearchQuery<'a, Http> { self.locales = Some(locales); self