diff --git a/meilisearch-core/src/settings.rs b/meilisearch-core/src/settings.rs index 0a9cdbb57..5e230cdba 100644 --- a/meilisearch-core/src/settings.rs +++ b/meilisearch-core/src/settings.rs @@ -105,12 +105,12 @@ pub enum RankingRule { impl std::fmt::Display for RankingRule { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - RankingRule::Typo => write!(f, "typo"), - RankingRule::Words => write!(f, "words"), - RankingRule::Proximity => write!(f, "proximity"), - RankingRule::Attribute => write!(f, "attribute"), - RankingRule::WordsPosition => write!(f, "words_position"), - RankingRule::Exactness => write!(f, "exactness"), + RankingRule::Typo => f.write_str("typo"), + RankingRule::Words => f.write_str("words"), + RankingRule::Proximity => f.write_str("proximity"), + RankingRule::Attribute => f.write_str("attribute"), + RankingRule::WordsPosition => f.write_str("wordsPosition"), + RankingRule::Exactness => f.write_str("exactness"), RankingRule::Asc(field) => write!(f, "asc({})", field), RankingRule::Dsc(field) => write!(f, "dsc({})", field), } diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index 33d1cc11b..d0f10eb80 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -84,7 +84,7 @@ pub fn apply_settings_update( must_reindex = true; }, UpdateState::Clear => { - schema.set_all_fields_indexed(); + schema.set_all_fields_as_indexed(); must_reindex = true; }, UpdateState::Nothing => (), @@ -92,7 +92,7 @@ pub fn apply_settings_update( match settings.displayed_attributes.clone() { UpdateState::Update(v) => schema.update_displayed(v)?, UpdateState::Clear => { - schema.set_all_fields_displayed(); + schema.set_all_fields_as_displayed(); }, UpdateState::Nothing => (), } diff --git a/meilisearch-http/src/data.rs b/meilisearch-http/src/data.rs index 3cd6a514b..5d05c02dd 100644 --- a/meilisearch-http/src/data.rs +++ b/meilisearch-http/src/data.rs @@ -6,8 +6,8 @@ use chrono::{DateTime, Utc}; use heed::types::{SerdeBincode, Str}; use log::error; use meilisearch_core::{Database, Error as MError, MResult, MainT, UpdateT}; -use sysinfo::Pid; use sha2::Digest; +use sysinfo::Pid; use crate::option::Opt; use crate::routes::index::index_update_callback; @@ -117,9 +117,7 @@ impl DataInner { // convert attributes to their names let frequency: HashMap<_, _> = fields_frequency .into_iter() - .filter_map(|(a, c)| { - schema.name(a).map(|name| (name.to_string(), c)) - }) + .filter_map(|(a, c)| schema.name(a).map(|name| (name.to_string(), c))) .collect(); index diff --git a/meilisearch-http/src/helpers/tide.rs b/meilisearch-http/src/helpers/tide.rs index 96003ce91..ce3bbe82a 100644 --- a/meilisearch-http/src/helpers/tide.rs +++ b/meilisearch-http/src/helpers/tide.rs @@ -6,7 +6,7 @@ use tide::Request; pub enum ACL { Admin, Private, - Public + Public, } pub trait RequestExt { @@ -23,31 +23,33 @@ impl RequestExt for Request { match acl { ACL::Admin => { if user_api_key == self.state().api_keys.master.as_deref() { - return Ok(()) + return Ok(()); } - }, + } ACL::Private => { if user_api_key == self.state().api_keys.master.as_deref() { - return Ok(()) + return Ok(()); } if user_api_key == self.state().api_keys.private.as_deref() { - return Ok(()) + return Ok(()); } - }, + } ACL::Public => { if user_api_key == self.state().api_keys.master.as_deref() { - return Ok(()) + return Ok(()); } if user_api_key == self.state().api_keys.private.as_deref() { - return Ok(()) + return Ok(()); } if user_api_key == self.state().api_keys.public.as_deref() { - return Ok(()) + return Ok(()); } } } - Err(ResponseError::InvalidToken(user_api_key.unwrap_or("Need a token").to_owned())) + Err(ResponseError::InvalidToken( + user_api_key.unwrap_or("Need a token").to_owned(), + )) } fn url_param(&self, name: &str) -> SResult { diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index 7d24e53a0..124bb9c47 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -18,19 +18,21 @@ mod analytics; static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; pub fn main() -> Result<(), MainError> { - let opt = Opt::from_args(); match opt.env.as_ref() { "production" => { if opt.master_key.is_none() { - return Err("In production mode, the environment variable MEILI_MASTER_KEY is mandatory".into()); + return Err( + "In production mode, the environment variable MEILI_MASTER_KEY is mandatory" + .into(), + ); } env_logger::init(); - }, + } "development" => { env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init(); - }, + } _ => unreachable!(), } @@ -58,7 +60,6 @@ pub fn main() -> Result<(), MainError> { Ok(()) } - pub fn print_launch_resume(opt: &Opt, data: &Data) { let ascii_name = r#" 888b d888 d8b 888 d8b .d8888b. 888 @@ -77,8 +78,14 @@ pub fn print_launch_resume(opt: &Opt, data: &Data) { info!("Start server on: {:?}", opt.http_addr); info!("Environment: {:?}", opt.env); info!("Commit SHA: {:?}", env!("VERGEN_SHA").to_string()); - info!("Build date: {:?}", env!("VERGEN_BUILD_TIMESTAMP").to_string()); - info!("Package version: {:?}", env!("CARGO_PKG_VERSION").to_string()); + info!( + "Build date: {:?}", + env!("VERGEN_BUILD_TIMESTAMP").to_string() + ); + info!( + "Package version: {:?}", + env!("CARGO_PKG_VERSION").to_string() + ); if let Some(master_key) = &data.api_keys.master { info!("Master Key: {:?}", master_key); diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index 1e70db296..e0ab4e88d 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -145,7 +145,7 @@ async fn update_multiple_documents(mut ctx: Request, is_partial: bool) -> None => return Err(ResponseError::bad_request("Could not infer a schema")), }, }; - let settings_update = SettingsUpdate{ + let settings_update = SettingsUpdate { identifier: UpdateState::Update(id), ..SettingsUpdate::default() }; diff --git a/meilisearch-http/src/routes/index.rs b/meilisearch-http/src/routes/index.rs index eb12145d0..6625d24c3 100644 --- a/meilisearch-http/src/routes/index.rs +++ b/meilisearch-http/src/routes/index.rs @@ -42,7 +42,7 @@ pub async fn list_indexes(ctx: Request) -> SResult { let identifier = match index.main.schema(&reader) { Ok(Some(schema)) => Some(schema.identifier().to_owned()), - _ => None + _ => None, }; let index_response = IndexResponse { @@ -89,7 +89,7 @@ pub async fn get_index(ctx: Request) -> SResult { let identifier = match index.main.schema(&reader) { Ok(Some(schema)) => Some(schema.identifier().to_owned()), - _ => None + _ => None, }; let response_body = IndexResponse { @@ -97,7 +97,7 @@ pub async fn get_index(ctx: Request) -> SResult { uid, created_at, updated_at, - identifier + identifier, }; Ok(tide::Response::new(200).body_json(&response_body)?) @@ -220,9 +220,13 @@ pub async fn update_index(mut ctx: Request) -> SResult { if let Some(identifier) = body.identifier { if let Ok(Some(_)) = index.main.schema(&writer) { - return Err(ResponseError::bad_request("The index identifier cannot be updated")); + return Err(ResponseError::bad_request( + "The index identifier cannot be updated", + )); } - index.main.put_schema(&mut writer, &Schema::with_identifier(&identifier))?; + index + .main + .put_schema(&mut writer, &Schema::with_identifier(&identifier))?; } index.main.put_updated_at(&mut writer)?; @@ -235,7 +239,7 @@ pub async fn update_index(mut ctx: Request) -> SResult { let identifier = match index.main.schema(&reader) { Ok(Some(schema)) => Some(schema.identifier().to_owned()), - _ => None + _ => None, }; let response_body = UpdateIndexResponse { @@ -243,7 +247,7 @@ pub async fn update_index(mut ctx: Request) -> SResult { uid: index_uid, created_at, updated_at, - identifier + identifier, }; Ok(tide::Response::new(200).body_json(&response_body)?) diff --git a/meilisearch-http/src/routes/key.rs b/meilisearch-http/src/routes/key.rs index 6ab85645b..fe0feacf4 100644 --- a/meilisearch-http/src/routes/key.rs +++ b/meilisearch-http/src/routes/key.rs @@ -1,18 +1,17 @@ -use tide::{Request, Response}; -use serde_json::json; use crate::error::SResult; use crate::helpers::tide::RequestExt; use crate::helpers::tide::ACL::*; use crate::Data; +use serde_json::json; +use tide::{Request, Response}; pub async fn list(ctx: Request) -> SResult { ctx.is_allowed(Admin)?; let keys = &ctx.state().api_keys; - Ok(tide::Response::new(200) - .body_json(&json!({ - "private": keys.private, - "public": keys.public, - }))?) + Ok(tide::Response::new(200).body_json(&json!({ + "private": keys.private, + "public": keys.public, + }))?) } diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 5caa765f5..e9188100a 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -23,19 +23,15 @@ async fn into_response( } pub fn load_routes(app: &mut tide::Server) { - app.at("/").get(|_| { - async move { - tide::Response::new(200) - .body_string(include_str!("../../public/interface.html").to_string()) - .set_mime(mime::TEXT_HTML_UTF_8) - } + app.at("/").get(|_| async { + tide::Response::new(200) + .body_string(include_str!("../../public/interface.html").to_string()) + .set_mime(mime::TEXT_HTML_UTF_8) }); - app.at("/bulma.min.css").get(|_| { - async { - tide::Response::new(200) - .body_string(include_str!("../../public/bulma.min.css").to_string()) - .set_mime(mime::TEXT_CSS_UTF_8) - } + app.at("/bulma.min.css").get(|_| async { + tide::Response::new(200) + .body_string(include_str!("../../public/bulma.min.css").to_string()) + .set_mime(mime::TEXT_CSS_UTF_8) }); app.at("/indexes") @@ -117,8 +113,7 @@ pub fn load_routes(app: &mut tide::Server) { app.at("/indexes/:index/stats") .get(|ctx| into_response(stats::index_stats(ctx))); - app.at("/keys/") - .get(|ctx| into_response(key::list(ctx))); + app.at("/keys/").get(|ctx| into_response(key::list(ctx))); app.at("/health") .get(|ctx| into_response(health::get_health(ctx))) diff --git a/meilisearch-http/src/routes/search.rs b/meilisearch-http/src/routes/search.rs index bfb8372aa..2dffd9356 100644 --- a/meilisearch-http/src/routes/search.rs +++ b/meilisearch-http/src/routes/search.rs @@ -7,10 +7,10 @@ use rayon::iter::{IntoParallelIterator, ParallelIterator}; use serde::{Deserialize, Serialize}; use tide::{Request, Response}; -use crate::helpers::tide::ACL::*; use crate::error::{ResponseError, SResult}; use crate::helpers::meilisearch::{Error, IndexSearchExt, SearchHit}; use crate::helpers::tide::RequestExt; +use crate::helpers::tide::ACL::*; use crate::Data; #[derive(Deserialize)] diff --git a/meilisearch-http/src/routes/setting.rs b/meilisearch-http/src/routes/setting.rs index 9b8c41a2f..b0b5ce8ea 100644 --- a/meilisearch-http/src/routes/setting.rs +++ b/meilisearch-http/src/routes/setting.rs @@ -46,7 +46,9 @@ pub async fn get_all(ctx: Request) -> SResult { None }; - let ranking_rules = index.main.ranking_rules(&reader)? + let ranking_rules = index + .main + .ranking_rules(&reader)? .unwrap_or(DEFAULT_RANKING_RULES.to_vec()) .into_iter() .map(|r| r.to_string()) @@ -57,7 +59,8 @@ pub async fn get_all(ctx: Request) -> SResult { let schema = index.main.schema(&reader)?; let searchable_attributes = schema.clone().map(|s| { - let attrs = s.indexed_name() + let attrs = s + .indexed_name() .iter() .map(|s| (*s).to_string()) .collect::>(); @@ -69,7 +72,8 @@ pub async fn get_all(ctx: Request) -> SResult { }); let displayed_attributes = schema.clone().map(|s| { - let attrs = s.displayed_name() + let attrs = s + .displayed_name() .iter() .map(|s| (*s).to_string()) .collect::>(); @@ -163,7 +167,9 @@ pub async fn get_rules(ctx: Request) -> SResult { let db = &ctx.state().db; let reader = db.main_read_txn()?; - let ranking_rules = index.main.ranking_rules(&reader)? + let ranking_rules = index + .main + .ranking_rules(&reader)? .unwrap_or(DEFAULT_RANKING_RULES.to_vec()) .into_iter() .map(|r| r.to_string()) diff --git a/meilisearch-http/tests/common.rs b/meilisearch-http/tests/common.rs index 3e7ca0608..2ab31ab15 100644 --- a/meilisearch-http/tests/common.rs +++ b/meilisearch-http/tests/common.rs @@ -179,7 +179,7 @@ pub fn wait_update_id(server: &mut TestBackend>, update_id: u64) { let response: Value = serde_json::from_slice(&buf).unwrap(); if response["status"] == "processed" { - return + return; } block_on(sleep(Duration::from_secs(1))); } diff --git a/meilisearch-schema/src/fields_map.rs b/meilisearch-schema/src/fields_map.rs index 6505b33fb..76d98f4da 100644 --- a/meilisearch-schema/src/fields_map.rs +++ b/meilisearch-schema/src/fields_map.rs @@ -52,7 +52,6 @@ impl FieldsMap { } } - #[cfg(test)] mod tests { use super::*; diff --git a/meilisearch-schema/src/schema.rs b/meilisearch-schema/src/schema.rs index da6d615b1..7a4180cb5 100644 --- a/meilisearch-schema/src/schema.rs +++ b/meilisearch-schema/src/schema.rs @@ -190,7 +190,7 @@ impl Schema { Ok(()) } - pub fn set_all_fields_indexed(&mut self) { + pub fn set_all_fields_as_indexed(&mut self) { self.indexed.clear(); self.indexed_map.clear(); @@ -201,7 +201,7 @@ impl Schema { } } - pub fn set_all_fields_displayed(&mut self) { + pub fn set_all_fields_as_displayed(&mut self) { self.displayed.clear(); for (_name, id) in self.fields_map.iter() {