fix clippy

This commit is contained in:
ManyTheFish 2024-07-23 15:19:07 +02:00 committed by Louis Dureuil
parent 4fbe048cbf
commit 70d71581ee
No known key found for this signature in database
7 changed files with 27 additions and 30 deletions

View File

@ -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.

View File

@ -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();

View File

@ -90,7 +90,7 @@ pub async fn search(
facet_name,
search_kind,
index_scheduler.features(),
locales
locales,
)
})
.await?;

View File

@ -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::<std::collections::BTreeSet<_>>())
"locales": rules.as_ref().map(|rules| rules.iter().flat_map(|rule| rule.locales.iter().cloned()).collect::<std::collections::BTreeSet<_>>())
}),
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::<std::collections::BTreeSet<_>>()),
"locales": new_settings.localized_attributes.as_ref().set().map(|rules| rules.iter().flat_map(|rule| rule.locales.iter().cloned()).collect::<std::collections::BTreeSet<_>>()),
}),
Some(&req),
);

View File

@ -1657,6 +1657,7 @@ fn make_document(
Ok(document)
}
#[allow(clippy::too_many_arguments)]
fn format_fields(
document: &Document,
field_ids_map: &FieldsIdsMap,

View File

@ -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<T> = std::result::Result<T, error::Error>;
pub type Attribute = u32;

View File

@ -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"));
}
}