From 70d71581eefbb494b369bff07bcff78f77993815 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Tue, 23 Jul 2024 15:19:07 +0200 Subject: [PATCH] fix clippy --- meilisearch-types/src/locales.rs | 3 +- .../src/analytics/segment_analytics.rs | 2 +- .../src/routes/indexes/facet_search.rs | 2 +- meilisearch/src/routes/indexes/settings.rs | 4 +- meilisearch/src/search/mod.rs | 1 + milli/src/lib.rs | 5 +-- milli/src/localized_attributes_rules.rs | 40 +++++++++---------- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/meilisearch-types/src/locales.rs b/meilisearch-types/src/locales.rs index 6f7fb3a40..8c15fe528 100644 --- a/meilisearch-types/src/locales.rs +++ b/meilisearch-types/src/locales.rs @@ -1,9 +1,8 @@ use deserr::Deserr; +use milli::LocalizedAttributesRule; use serde::{Deserialize, Serialize}; use serde_json::json; -use milli::LocalizedAttributesRule; - /// Generate a Locale enum and its From and Into implementations for milli::tokenizer::Language. /// /// this enum implements `Deserr` in order to be used in the API. diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 407b90658..07350d506 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -780,7 +780,7 @@ impl SearchAggregator { ret.matching_strategy.insert(format!("{:?}", matching_strategy), 1); if let Some(locales) = locales { - ret.locales = locales.into_iter().copied().collect(); + ret.locales = locales.iter().copied().collect(); } ret.highlight_pre_tag = *highlight_pre_tag != DEFAULT_HIGHLIGHT_PRE_TAG(); diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index da575fdc4..a648987ca 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -90,7 +90,7 @@ pub async fn search( facet_name, search_kind, index_scheduler.features(), - locales + locales, ) }) .await?; diff --git a/meilisearch/src/routes/indexes/settings.rs b/meilisearch/src/routes/indexes/settings.rs index b62690295..6f081f1c7 100644 --- a/meilisearch/src/routes/indexes/settings.rs +++ b/meilisearch/src/routes/indexes/settings.rs @@ -489,7 +489,7 @@ make_setting_route!( analytics.publish( "LocalizedAttributesRules Updated".to_string(), json!({ - "locales": rules.as_ref().map(|rules| rules.iter().map(|rule| rule.locales.iter().cloned()).flatten().collect::>()) + "locales": rules.as_ref().map(|rules| rules.iter().flat_map(|rule| rule.locales.iter().cloned()).collect::>()) }), Some(req), ); @@ -808,7 +808,7 @@ pub async fn update_all( }, "embedders": crate::routes::indexes::settings::embedder_analytics(new_settings.embedders.as_ref().set()), "search_cutoff_ms": new_settings.search_cutoff_ms.as_ref().set(), - "locales": new_settings.localized_attributes.as_ref().set().map(|rules| rules.into_iter().map(|rule| rule.locales.iter().cloned()).flatten().collect::>()), + "locales": new_settings.localized_attributes.as_ref().set().map(|rules| rules.iter().flat_map(|rule| rule.locales.iter().cloned()).collect::>()), }), Some(&req), ); diff --git a/meilisearch/src/search/mod.rs b/meilisearch/src/search/mod.rs index 11bf4f84e..dada9159b 100644 --- a/meilisearch/src/search/mod.rs +++ b/meilisearch/src/search/mod.rs @@ -1657,6 +1657,7 @@ fn make_document( Ok(document) } +#[allow(clippy::too_many_arguments)] fn format_fields( document: &Document, field_ids_map: &FieldsIdsMap, diff --git a/milli/src/lib.rs b/milli/src/lib.rs index 461971ddf..8008b7bd1 100644 --- a/milli/src/lib.rs +++ b/milli/src/lib.rs @@ -63,6 +63,8 @@ pub use self::heed_codec::{ UncheckedU8StrStrCodec, }; pub use self::index::Index; +pub use self::localized_attributes_rules::LocalizedAttributesRule; +use self::localized_attributes_rules::LocalizedFieldIds; pub use self::search::facet::{FacetValueHit, SearchForFacetValues}; pub use self::search::similar::Similar; pub use self::search::{ @@ -70,9 +72,6 @@ pub use self::search::{ Search, SearchResult, SemanticSearch, TermsMatchingStrategy, DEFAULT_VALUES_PER_FACET, }; -pub use self::localized_attributes_rules::LocalizedAttributesRule; -use self::localized_attributes_rules::LocalizedFieldIds; - pub type Result = std::result::Result; pub type Attribute = u32; diff --git a/milli/src/localized_attributes_rules.rs b/milli/src/localized_attributes_rules.rs index a3b3e820b..aa4eddee1 100644 --- a/milli/src/localized_attributes_rules.rs +++ b/milli/src/localized_attributes_rules.rs @@ -35,19 +35,17 @@ impl LocalizedAttributesRule { } fn match_pattern(pattern: &str, str: &str) -> bool { - let res = if pattern == "*" { + if pattern == "*" { true } else if pattern.starts_with('*') && pattern.ends_with('*') { str.contains(&pattern[1..pattern.len() - 1]) - } else if pattern.ends_with('*') { - str.starts_with(&pattern[..pattern.len() - 1]) - } else if pattern.starts_with('*') { - str.ends_with(&pattern[1..]) + } else if let Some(pattern) = pattern.strip_prefix('*') { + str.ends_with(pattern) + } else if let Some(pattern) = pattern.strip_suffix('*') { + str.starts_with(pattern) } else { pattern == str - }; - - res + } } #[derive(Debug, Clone, PartialEq, Eq)] @@ -87,7 +85,7 @@ impl LocalizedFieldIds { Self { field_id_to_locales } } - pub fn locales<'a>(&'a self, fields_id: FieldId) -> Option<&'a [Language]> { + pub fn locales(&self, fields_id: FieldId) -> Option<&[Language]> { self.field_id_to_locales.get(&fields_id).map(Vec::as_slice) } } @@ -98,17 +96,17 @@ mod tests { #[test] fn test_match_pattern() { - assert_eq!(match_pattern("*", "test"), true); - assert_eq!(match_pattern("test*", "test"), true); - assert_eq!(match_pattern("test*", "testa"), true); - assert_eq!(match_pattern("*test", "test"), true); - assert_eq!(match_pattern("*test", "atest"), true); - assert_eq!(match_pattern("*test*", "test"), true); - assert_eq!(match_pattern("*test*", "atesta"), true); - assert_eq!(match_pattern("*test*", "atest"), true); - assert_eq!(match_pattern("*test*", "testa"), true); - assert_eq!(match_pattern("test*test", "test"), false); - assert_eq!(match_pattern("*test", "testa"), false); - assert_eq!(match_pattern("test*", "atest"), false); + assert!(match_pattern("*", "test")); + assert!(match_pattern("test*", "test")); + assert!(match_pattern("test*", "testa")); + assert!(match_pattern("*test", "test")); + assert!(match_pattern("*test", "atest")); + assert!(match_pattern("*test*", "test")); + assert!(match_pattern("*test*", "atesta")); + assert!(match_pattern("*test*", "atest")); + assert!(match_pattern("*test*", "testa")); + assert!(!match_pattern("test*test", "test")); + assert!(!match_pattern("*test", "testa")); + assert!(!match_pattern("test*", "atest")); } }