-
Notifications
You must be signed in to change notification settings - Fork 103
Add filterableAttributes syntax API to settings #730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
b926f13
873f112
89f6c6b
b1bd536
afabcf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,55 @@ pub struct FacetingSettings { | |
| pub sort_facet_values_by: Option<BTreeMap<String, FacetSortValue>>, | ||
| } | ||
|
|
||
| /// Filterable attribute settings. | ||
| /// | ||
| /// Meilisearch supports a mixed syntax: either a plain attribute name | ||
| /// (string) or an object describing patterns and feature flags. This SDK | ||
| /// models it with `FilterableAttribute` (untagged enum) and associated | ||
| /// settings structs. | ||
| #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct FilterFeatureModes { | ||
| pub equality: bool, | ||
| pub comparison: bool, | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct FilterFeatures { | ||
| pub facet_search: bool, | ||
| pub filter: FilterFeatureModes, | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct FilterableAttributesSettings { | ||
| #[serde(rename = "attributePatterns")] | ||
| pub attribute_patterns: Vec<String>, | ||
| pub features: FilterFeatures, | ||
| } | ||
|
|
||
| /// A filterable attribute definition, either a plain attribute name or a | ||
| /// settings object. | ||
| #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] | ||
| #[serde(untagged)] | ||
| pub enum FilterableAttribute { | ||
| Attribute(String), | ||
| Settings(FilterableAttributesSettings), | ||
| } | ||
|
|
||
| impl From<String> for FilterableAttribute { | ||
| fn from(value: String) -> Self { | ||
| FilterableAttribute::Attribute(value) | ||
| } | ||
| } | ||
|
|
||
| impl From<&str> for FilterableAttribute { | ||
| fn from(value: &str) -> Self { | ||
| FilterableAttribute::Attribute(value.to_string()) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub enum EmbedderSource { | ||
|
|
@@ -193,8 +242,10 @@ pub struct Settings { | |
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub ranking_rules: Option<Vec<String>>, | ||
| /// Attributes to use for [filtering](https://www.meilisearch.com/docs/learn/advanced/filtering). | ||
| /// | ||
| /// Supports both plain attribute names and settings objects. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub filterable_attributes: Option<Vec<String>>, | ||
| pub filterable_attributes: Option<Vec<FilterableAttribute>>, | ||
|
Comment on lines
+259
to
+262
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify migration path for breaking change to filterable_attributes field. The type change from Consider:
Run the following script to identify potential usage patterns in the codebase: 🏁 Script executed: #!/bin/bash
# Find direct field access or struct construction patterns
rg -nP --type=rust -C3 'Settings\s*\{.*filterable_attributes' -g '!src/settings.rs'
rg -nP --type=rust -C3 '\.filterable_attributes\s*=' -g '!src/settings.rs'Length of output: 0 Length of output: 11128 Breaking change confirmed: direct field access to Direct field access exists in the codebase (e.g., The builder methods ( |
||
| /// Attributes to sort. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub sortable_attributes: Option<Vec<String>>, | ||
|
|
@@ -324,16 +375,29 @@ impl Settings { | |
| filterable_attributes: impl IntoIterator<Item = impl AsRef<str>>, | ||
| ) -> Settings { | ||
| Settings { | ||
| // Legacy helper accepting a list of attribute names. | ||
| filterable_attributes: Some( | ||
| filterable_attributes | ||
| .into_iter() | ||
| .map(|v| v.as_ref().to_string()) | ||
| .map(|v| FilterableAttribute::Attribute(v.as_ref().to_string())) | ||
| .collect(), | ||
| ), | ||
| ..self | ||
| } | ||
| } | ||
|
|
||
| /// Set filterable attributes using mixed syntax. | ||
| #[must_use] | ||
| pub fn with_filterable_attributes_advanced( | ||
| self, | ||
| filterable_attributes: impl IntoIterator<Item = FilterableAttribute>, | ||
| ) -> Settings { | ||
| Settings { | ||
| filterable_attributes: Some(filterable_attributes.into_iter().collect()), | ||
| ..self | ||
| } | ||
| } | ||
|
|
||
| #[must_use] | ||
| pub fn with_sortable_attributes( | ||
| self, | ||
|
|
@@ -714,6 +778,26 @@ impl<Http: HttpClient> Index<Http> { | |
| .await | ||
| } | ||
|
|
||
| /// Get filterable attributes using mixed syntax. | ||
| /// | ||
| /// Returns a list that can contain plain attribute names (strings) and/or | ||
| /// settings objects. | ||
| pub async fn get_filterable_attributes_advanced( | ||
| &self, | ||
| ) -> Result<Vec<FilterableAttribute>, Error> { | ||
| self.client | ||
| .http_client | ||
| .request::<(), (), Vec<FilterableAttribute>>( | ||
| &format!( | ||
| "{}/indexes/{}/settings/filterable-attributes", | ||
| self.client.host, self.uid | ||
| ), | ||
| Method::Get { query: () }, | ||
| 200, | ||
| ) | ||
| .await | ||
| } | ||
|
|
||
| /// Get [sortable attributes](https://www.meilisearch.com/docs/reference/api/settings#sortable-attributes) of the [Index]. | ||
| /// | ||
| /// # Example | ||
|
|
@@ -1507,9 +1591,10 @@ impl<Http: HttpClient> Index<Http> { | |
| &self, | ||
| filterable_attributes: impl IntoIterator<Item = impl AsRef<str>>, | ||
| ) -> Result<TaskInfo, Error> { | ||
| // Backward-compatible helper: accept a list of attribute names. | ||
| self.client | ||
| .http_client | ||
| .request::<(), Vec<String>, TaskInfo>( | ||
| .request::<(), Vec<FilterableAttribute>, TaskInfo>( | ||
| &format!( | ||
| "{}/indexes/{}/settings/filterable-attributes", | ||
| self.client.host, self.uid | ||
|
|
@@ -1518,14 +1603,35 @@ impl<Http: HttpClient> Index<Http> { | |
| query: (), | ||
| body: filterable_attributes | ||
| .into_iter() | ||
| .map(|v| v.as_ref().to_string()) | ||
| .map(|v| FilterableAttribute::Attribute(v.as_ref().to_string())) | ||
| .collect(), | ||
| }, | ||
| 202, | ||
| ) | ||
| .await | ||
| } | ||
|
|
||
| /// Update filterable attributes using mixed syntax. | ||
| pub async fn set_filterable_attributes_advanced( | ||
| &self, | ||
| filterable_attributes: impl IntoIterator<Item = FilterableAttribute>, | ||
| ) -> Result<TaskInfo, Error> { | ||
| self.client | ||
| .http_client | ||
| .request::<(), Vec<FilterableAttribute>, TaskInfo>( | ||
| &format!( | ||
| "{}/indexes/{}/settings/filterable-attributes", | ||
| self.client.host, self.uid | ||
| ), | ||
| Method::Put { | ||
| query: (), | ||
| body: filterable_attributes.into_iter().collect(), | ||
| }, | ||
| 202, | ||
| ) | ||
| .await | ||
| } | ||
|
|
||
| /// Update [sortable attributes](https://www.meilisearch.com/docs/reference/api/settings#sortable-attributes) of the [Index]. | ||
| /// | ||
| /// # Example | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.