diff --git a/src/channel/command.rs b/src/channel/command.rs index 5d19cc5c..ed3147ad 100644 --- a/src/channel/command.rs +++ b/src/channel/command.rs @@ -7,6 +7,7 @@ use hashbrown::HashMap; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; +use std::fmt; use std::path::Path; use std::str::{self, SplitWhitespace}; use std::vec::Vec; @@ -33,6 +34,26 @@ pub enum ChannelCommandError { InvalidMetaValue((String, String)), } +impl fmt::Display for ChannelCommandError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + match self { + ChannelCommandError::UnknownCommand => write!(f, "unknown_command"), + ChannelCommandError::NotFound => write!(f, "not_found"), + ChannelCommandError::QueryError => write!(f, "query_error"), + ChannelCommandError::InternalError => write!(f, "internal_error"), + ChannelCommandError::ShuttingDown => write!(f, "shutting_down"), + ChannelCommandError::PolicyReject(reason) => write!(f, "policy_reject({})", reason), + ChannelCommandError::InvalidFormat(format) => write!(f, "invalid_format({})", format), + ChannelCommandError::InvalidMetaKey(ref data) => { + write!(f, "invalid_meta_key({}[{}])", data.0, data.1) + } + ChannelCommandError::InvalidMetaValue(ref data) => { + write!(f, "invalid_meta_value({}[{}])", data.0, data.1) + } + } + } +} + #[derive(PartialEq)] pub enum ChannelCommandResponse { Void, @@ -62,8 +83,8 @@ const TEXT_PART_ESCAPE: char = '\\'; const META_PART_GROUP_OPEN: char = '('; const META_PART_GROUP_CLOSE: char = ')'; -static BACKUP_KV_PATH: &'static str = "kv"; -static BACKUP_FST_PATH: &'static str = "fst"; +static BACKUP_KV_PATH: &str = "kv"; +static BACKUP_FST_PATH: &str = "fst"; lazy_static! { pub static ref COMMANDS_MODE_SEARCH: Vec<&'static str> = @@ -91,26 +112,6 @@ lazy_static! { .collect(); } -impl ChannelCommandError { - pub fn to_string(&self) -> String { - match *self { - ChannelCommandError::UnknownCommand => String::from("unknown_command"), - ChannelCommandError::NotFound => String::from("not_found"), - ChannelCommandError::QueryError => String::from("query_error"), - ChannelCommandError::InternalError => String::from("internal_error"), - ChannelCommandError::ShuttingDown => String::from("shutting_down"), - ChannelCommandError::PolicyReject(reason) => format!("policy_reject({})", reason), - ChannelCommandError::InvalidFormat(format) => format!("invalid_format({})", format), - ChannelCommandError::InvalidMetaKey(ref data) => { - format!("invalid_meta_key({}[{}])", data.0, data.1) - } - ChannelCommandError::InvalidMetaValue(ref data) => { - format!("invalid_meta_value({}[{}])", data.0, data.1) - } - } - } -} - impl ChannelCommandResponse { pub fn to_args(&self) -> ChannelCommandResponseArgs { // Convert internal response to channel response arguments; this either gives 'RESPONSE' \ @@ -181,9 +182,9 @@ impl ChannelCommandBase { // Parse text parts and nest them together let mut text_raw = String::new(); - while let Some(text_part) = parts.next() { + for text_part in parts { if !text_raw.is_empty() { - text_raw.push_str(" "); + text_raw.push(' '); } text_raw.push_str(text_part); @@ -315,14 +316,14 @@ impl ChannelCommandBase { pub fn commit_ok_operation(query_builder: QueryBuilderResult) -> ChannelResult { query_builder - .and_then(|query| StoreOperationDispatch::dispatch(query)) - .and_then(|_| Ok(vec![ChannelCommandResponse::Ok])) + .and_then(StoreOperationDispatch::dispatch) + .map(|_| vec![ChannelCommandResponse::Ok]) .or(Err(ChannelCommandError::QueryError)) } pub fn commit_result_operation(query_builder: QueryBuilderResult) -> ChannelResult { query_builder - .and_then(|query| StoreOperationDispatch::dispatch(query)) + .and_then(StoreOperationDispatch::dispatch) .or(Err(ChannelCommandError::QueryError)) .and_then(|result| { if let Some(result_inner) = result { @@ -333,10 +334,10 @@ impl ChannelCommandBase { }) } - pub fn commit_pending_operation<'a>( + pub fn commit_pending_operation( query_type: &'static str, query_id: &str, - query_builder: QueryBuilderResult<'a>, + query_builder: QueryBuilderResult, ) -> ChannelResult { // Idea: this could be made asynchronous in the future, if there are some latency issues \ // on large Sonic deployments. The idea would be to have a number of worker threads for \ @@ -348,16 +349,16 @@ impl ChannelCommandBase { // consumer via a worker thread pool. query_builder - .and_then(|query| StoreOperationDispatch::dispatch(query)) - .and_then(|results| { - Ok(vec![ + .and_then(StoreOperationDispatch::dispatch) + .map(|results| { + vec![ ChannelCommandResponse::Pending(query_id.to_string()), ChannelCommandResponse::Event( query_type, query_id.to_string(), - results.unwrap_or(String::new()), + results.unwrap_or_default(), ), - ]) + ] }) .or(Err(ChannelCommandError::QueryError)) } @@ -371,6 +372,12 @@ impl ChannelCommandBase { } } +type QueryMetaData = ( + Option, + Option, + Option, +); + impl ChannelCommandSearch { pub fn dispatch_query(mut parts: SplitWhitespace) -> ChannelResult { match ( @@ -512,14 +519,7 @@ impl ChannelCommandSearch { fn handle_query_meta( meta_result: MetaPartsResult, - ) -> Result< - ( - Option, - Option, - Option, - ), - ChannelCommandError, - > { + ) -> Result { match meta_result { Ok((meta_key, meta_value)) => { debug!("handle query meta: {} = {}", meta_key, meta_value); @@ -531,8 +531,7 @@ impl ChannelCommandSearch { Ok((Some(query_limit_parsed), None, None)) } else { Err(ChannelCommandBase::make_error_invalid_meta_value( - &meta_key, - &meta_value, + meta_key, meta_value, )) } } @@ -542,8 +541,7 @@ impl ChannelCommandSearch { Ok((None, Some(query_offset_parsed), None)) } else { Err(ChannelCommandBase::make_error_invalid_meta_value( - &meta_key, - &meta_value, + meta_key, meta_value, )) } } @@ -553,19 +551,17 @@ impl ChannelCommandSearch { Ok((None, None, Some(query_lang_parsed))) } else { Err(ChannelCommandBase::make_error_invalid_meta_value( - &meta_key, - &meta_value, + meta_key, meta_value, )) } } _ => Err(ChannelCommandBase::make_error_invalid_meta_key( - &meta_key, - &meta_value, + meta_key, meta_value, )), } } Err(err) => Err(ChannelCommandBase::make_error_invalid_meta_key( - &err.0, &err.1, + err.0, err.1, )), } } @@ -584,19 +580,17 @@ impl ChannelCommandSearch { Ok(Some(suggest_limit_parsed)) } else { Err(ChannelCommandBase::make_error_invalid_meta_value( - &meta_key, - &meta_value, + meta_key, meta_value, )) } } _ => Err(ChannelCommandBase::make_error_invalid_meta_key( - &meta_key, - &meta_value, + meta_key, meta_value, )), } } Err(err) => Err(ChannelCommandBase::make_error_invalid_meta_key( - &err.0, &err.1, + err.0, err.1, )), } } @@ -767,19 +761,17 @@ impl ChannelCommandIngest { Ok(Some(query_lang_parsed)) } else { Err(ChannelCommandBase::make_error_invalid_meta_value( - &meta_key, - &meta_value, + meta_key, meta_value, )) } } _ => Err(ChannelCommandBase::make_error_invalid_meta_key( - &meta_key, - &meta_value, + meta_key, meta_value, )), } } Err(err) => Err(ChannelCommandBase::make_error_invalid_meta_key( - &err.0, &err.1, + err.0, err.1, )), } } diff --git a/src/channel/handle.rs b/src/channel/handle.rs index 9b5d11f5..7b52740e 100644 --- a/src/channel/handle.rs +++ b/src/channel/handle.rs @@ -39,7 +39,7 @@ const BUFFER_SIZE: usize = 20000; const MAX_LINE_SIZE: usize = BUFFER_SIZE + LINE_END_GAP + 1; const TCP_TIMEOUT_NON_ESTABLISHED: u64 = 10; const PROTOCOL_REVISION: u8 = 1; -const BUFFER_LINE_SEPARATOR: u8 = '\n' as u8; +const BUFFER_LINE_SEPARATOR: u8 = b'\n'; lazy_static! { static ref CONNECTED_BANNER: String = format!( @@ -192,6 +192,7 @@ impl ChannelHandle { } fn ensure_start(mut stream: &TcpStream) -> Result { + #[allow(clippy::never_loop)] loop { let mut read = [0; MAX_LINE_SIZE]; diff --git a/src/channel/message.rs b/src/channel/message.rs index b07686e7..6f353649 100644 --- a/src/channel/message.rs +++ b/src/channel/message.rs @@ -51,13 +51,13 @@ impl ChannelMessage { // Process response for issued command let response_args_groups: Vec; - if *CHANNEL_AVAILABLE.read().unwrap() != true { + if !(*CHANNEL_AVAILABLE.read().unwrap()) { // Server going down, reject command response_args_groups = vec![ChannelCommandResponse::Err(ChannelCommandError::ShuttingDown).to_args()]; } else { // Handle response arguments to issued command - response_args_groups = match M::handle(&message) { + response_args_groups = match M::handle(message) { Ok(resp_groups) => resp_groups .iter() .map(|resp| match resp { diff --git a/src/config/config.rs b/src/config/config.rs deleted file mode 100644 index 0f4d8787..00000000 --- a/src/config/config.rs +++ /dev/null @@ -1,145 +0,0 @@ -// Sonic -// -// Fast, lightweight and schema-less search backend -// Copyright: 2019, Valerian Saliou -// License: Mozilla Public License v2.0 (MPL v2.0) - -use std::net::SocketAddr; -use std::path::PathBuf; - -use super::defaults; -use super::env_var; - -#[derive(Deserialize)] -pub struct Config { - pub server: ConfigServer, - pub channel: ConfigChannel, - pub store: ConfigStore, -} - -#[derive(Deserialize)] -pub struct ConfigServer { - #[serde( - default = "defaults::server_log_level", - deserialize_with = "env_var::str" - )] - pub log_level: String, -} - -#[derive(Deserialize)] -pub struct ConfigChannel { - #[serde( - default = "defaults::channel_inet", - deserialize_with = "env_var::socket_addr" - )] - pub inet: SocketAddr, - - #[serde(default = "defaults::channel_tcp_timeout")] - pub tcp_timeout: u64, - - #[serde(default, deserialize_with = "env_var::opt_str")] - pub auth_password: Option, - - pub search: ConfigChannelSearch, -} - -#[derive(Deserialize)] -pub struct ConfigChannelSearch { - #[serde(default = "defaults::channel_search_query_limit_default")] - pub query_limit_default: u16, - - #[serde(default = "defaults::channel_search_query_limit_maximum")] - pub query_limit_maximum: u16, - - #[serde(default = "defaults::channel_search_query_alternates_try")] - pub query_alternates_try: usize, - - #[serde(default = "defaults::channel_search_suggest_limit_default")] - pub suggest_limit_default: u16, - - #[serde(default = "defaults::channel_search_suggest_limit_maximum")] - pub suggest_limit_maximum: u16, -} - -#[derive(Deserialize)] -pub struct ConfigStore { - pub kv: ConfigStoreKV, - pub fst: ConfigStoreFST, -} - -#[derive(Deserialize)] -pub struct ConfigStoreKV { - #[serde( - default = "defaults::store_kv_path", - deserialize_with = "env_var::path_buf" - )] - pub path: PathBuf, - - #[serde(default = "defaults::store_kv_retain_word_objects")] - pub retain_word_objects: usize, - - pub pool: ConfigStoreKVPool, - pub database: ConfigStoreKVDatabase, -} - -#[derive(Deserialize)] -pub struct ConfigStoreKVPool { - #[serde(default = "defaults::store_kv_pool_inactive_after")] - pub inactive_after: u64, -} - -#[derive(Deserialize)] -pub struct ConfigStoreKVDatabase { - #[serde(default = "defaults::store_kv_database_flush_after")] - pub flush_after: u64, - - #[serde(default = "defaults::store_kv_database_compress")] - pub compress: bool, - - #[serde(default = "defaults::store_kv_database_parallelism")] - pub parallelism: u16, - - pub max_files: Option, - - #[serde(default = "defaults::store_kv_database_max_compactions")] - pub max_compactions: u16, - - #[serde(default = "defaults::store_kv_database_max_flushes")] - pub max_flushes: u16, - - #[serde(default = "defaults::store_kv_database_write_buffer")] - pub write_buffer: usize, - - #[serde(default = "defaults::store_kv_database_write_ahead_log")] - pub write_ahead_log: bool, -} - -#[derive(Deserialize)] -pub struct ConfigStoreFST { - #[serde( - default = "defaults::store_fst_path", - deserialize_with = "env_var::path_buf" - )] - pub path: PathBuf, - - pub pool: ConfigStoreFSTPool, - pub graph: ConfigStoreFSTGraph, -} - -#[derive(Deserialize)] -pub struct ConfigStoreFSTPool { - #[serde(default = "defaults::store_fst_pool_inactive_after")] - pub inactive_after: u64, -} - -#[derive(Deserialize)] -pub struct ConfigStoreFSTGraph { - #[serde(default = "defaults::store_fst_graph_consolidate_after")] - pub consolidate_after: u64, - - #[serde(default = "defaults::store_fst_graph_max_size")] - pub max_size: usize, - - #[serde(default = "defaults::store_fst_graph_max_words")] - pub max_words: usize, -} diff --git a/src/config/env_var.rs b/src/config/env_var.rs index 415508e2..6638813a 100644 --- a/src/config/env_var.rs +++ b/src/config/env_var.rs @@ -18,8 +18,8 @@ where { let value = String::deserialize(deserializer)?; - match self::is_env_var(&value) { - true => Ok(self::get_env_var(&value)), + match is_env_var(&value) { + true => Ok(get_env_var(&value)), false => Ok(value), } } @@ -32,8 +32,8 @@ where option.map(|wrapped: WrappedString| { let value = wrapped.0; - match self::is_env_var(&value) { - true => self::get_env_var(&value), + match is_env_var(&value) { + true => get_env_var(&value), false => value, } }) @@ -46,8 +46,8 @@ where { let value = String::deserialize(deserializer)?; - match self::is_env_var(&value) { - true => Ok(self::get_env_var(&value).parse().unwrap()), + match is_env_var(&value) { + true => Ok(get_env_var(&value).parse().unwrap()), false => Ok(value.parse().unwrap()), } } @@ -58,8 +58,8 @@ where { let value = String::deserialize(deserializer)?; - match self::is_env_var(&value) { - true => Ok(PathBuf::from(self::get_env_var(&value))), + match is_env_var(&value) { + true => Ok(PathBuf::from(get_env_var(&value))), false => Ok(PathBuf::from(value)), } } @@ -75,7 +75,7 @@ fn get_env_var(wrapped_key: &str) -> String { .drain(6..(wrapped_key.len() - 1)) .collect(); - std::env::var(key.clone()).expect(&format!("env_var: variable '{}' is not set", key)) + std::env::var(key.clone()).unwrap_or_else(|_| panic!("env_var: variable '{}' is not set", key)) } #[cfg(test)] @@ -84,22 +84,22 @@ mod tests { #[test] fn it_checks_environment_variable_patterns() { - assert_eq!(self::is_env_var("${env.XXX}"), true); - assert_eq!(self::is_env_var("${env.XXX"), false); - assert_eq!(self::is_env_var("${env.XXX}a"), false); - assert_eq!(self::is_env_var("a${env.XXX}"), false); - assert_eq!(self::is_env_var("{env.XXX}"), false); - assert_eq!(self::is_env_var("$env.XXX}"), false); - assert_eq!(self::is_env_var("${envXXX}"), false); - assert_eq!(self::is_env_var("${.XXX}"), false); - assert_eq!(self::is_env_var("${XXX}"), false); + assert!(is_env_var("${env.XXX}")); + assert!(!is_env_var("${env.XXX")); + assert!(!is_env_var("${env.XXX}a")); + assert!(!is_env_var("a${env.XXX}")); + assert!(!is_env_var("{env.XXX}")); + assert!(!is_env_var("$env.XXX}")); + assert!(!is_env_var("${envXXX}")); + assert!(!is_env_var("${.XXX}")); + assert!(!is_env_var("${XXX}")); } #[test] fn it_gets_environment_variable() { std::env::set_var("TEST", "test"); - assert_eq!(self::get_env_var("${env.TEST}"), "test"); + assert_eq!(get_env_var("${env.TEST}"), "test"); std::env::remove_var("TEST"); } diff --git a/src/config/logger.rs b/src/config/logger.rs index e563936d..8aeccb6e 100644 --- a/src/config/logger.rs +++ b/src/config/logger.rs @@ -4,7 +4,6 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -use log; use log::{Level, LevelFilter, Metadata, Record, SetLoggerError}; pub struct ConfigLogger; diff --git a/src/config/mod.rs b/src/config/mod.rs index 29e91526..9c0eb5f5 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -7,6 +7,142 @@ mod defaults; mod env_var; -pub mod config; pub mod logger; pub mod reader; + +use std::net::SocketAddr; +use std::path::PathBuf; + +#[derive(Deserialize)] +pub struct Config { + pub server: ConfigServer, + pub channel: ConfigChannel, + pub store: ConfigStore, +} + +#[derive(Deserialize)] +pub struct ConfigServer { + #[serde( + default = "defaults::server_log_level", + deserialize_with = "env_var::str" + )] + pub log_level: String, +} + +#[derive(Deserialize)] +pub struct ConfigChannel { + #[serde( + default = "defaults::channel_inet", + deserialize_with = "env_var::socket_addr" + )] + pub inet: SocketAddr, + + #[serde(default = "defaults::channel_tcp_timeout")] + pub tcp_timeout: u64, + + #[serde(default, deserialize_with = "env_var::opt_str")] + pub auth_password: Option, + + pub search: ConfigChannelSearch, +} + +#[derive(Deserialize)] +pub struct ConfigChannelSearch { + #[serde(default = "defaults::channel_search_query_limit_default")] + pub query_limit_default: u16, + + #[serde(default = "defaults::channel_search_query_limit_maximum")] + pub query_limit_maximum: u16, + + #[serde(default = "defaults::channel_search_query_alternates_try")] + pub query_alternates_try: usize, + + #[serde(default = "defaults::channel_search_suggest_limit_default")] + pub suggest_limit_default: u16, + + #[serde(default = "defaults::channel_search_suggest_limit_maximum")] + pub suggest_limit_maximum: u16, +} + +#[derive(Deserialize)] +pub struct ConfigStore { + pub kv: ConfigStoreKV, + pub fst: ConfigStoreFST, +} + +#[derive(Deserialize)] +pub struct ConfigStoreKV { + #[serde( + default = "defaults::store_kv_path", + deserialize_with = "env_var::path_buf" + )] + pub path: PathBuf, + + #[serde(default = "defaults::store_kv_retain_word_objects")] + pub retain_word_objects: usize, + + pub pool: ConfigStoreKVPool, + pub database: ConfigStoreKVDatabase, +} + +#[derive(Deserialize)] +pub struct ConfigStoreKVPool { + #[serde(default = "defaults::store_kv_pool_inactive_after")] + pub inactive_after: u64, +} + +#[derive(Deserialize)] +pub struct ConfigStoreKVDatabase { + #[serde(default = "defaults::store_kv_database_flush_after")] + pub flush_after: u64, + + #[serde(default = "defaults::store_kv_database_compress")] + pub compress: bool, + + #[serde(default = "defaults::store_kv_database_parallelism")] + pub parallelism: u16, + + pub max_files: Option, + + #[serde(default = "defaults::store_kv_database_max_compactions")] + pub max_compactions: u16, + + #[serde(default = "defaults::store_kv_database_max_flushes")] + pub max_flushes: u16, + + #[serde(default = "defaults::store_kv_database_write_buffer")] + pub write_buffer: usize, + + #[serde(default = "defaults::store_kv_database_write_ahead_log")] + pub write_ahead_log: bool, +} + +#[derive(Deserialize)] +pub struct ConfigStoreFST { + #[serde( + default = "defaults::store_fst_path", + deserialize_with = "env_var::path_buf" + )] + pub path: PathBuf, + + pub pool: ConfigStoreFSTPool, + pub graph: ConfigStoreFSTGraph, +} + +#[derive(Deserialize)] +pub struct ConfigStoreFSTPool { + #[serde(default = "defaults::store_fst_pool_inactive_after")] + pub inactive_after: u64, +} + +#[derive(Deserialize)] +pub struct ConfigStoreFSTGraph { + #[serde(default = "defaults::store_fst_graph_consolidate_after")] + pub consolidate_after: u64, + + #[serde(default = "defaults::store_fst_graph_max_size")] + pub max_size: usize, + + #[serde(default = "defaults::store_fst_graph_max_words")] + pub max_words: usize, +} diff --git a/src/config/reader.rs b/src/config/reader.rs index 0ab6fa58..e21cf572 100644 --- a/src/config/reader.rs +++ b/src/config/reader.rs @@ -6,9 +6,8 @@ use std::fs::File; use std::io::Read; -use toml; -use super::config::*; +use super::Config; use crate::APP_ARGS; pub struct ConfigReader; diff --git a/src/executor/flusho.rs b/src/executor/flusho.rs index 6cff0909..a65acc60 100644 --- a/src/executor/flusho.rs +++ b/src/executor/flusho.rs @@ -33,7 +33,7 @@ impl ExecutorFlushO { // Resolve terms associated to IID let iid_terms = { if let Ok(iid_terms_value) = kv_action.get_iid_to_terms(iid) { - iid_terms_value.unwrap_or(Vec::new()) + iid_terms_value.unwrap_or_default() } else { error!("failed getting flusho executor iid-to-terms"); diff --git a/src/executor/pop.rs b/src/executor/pop.rs index 3d5c70c9..f544cd5c 100644 --- a/src/executor/pop.rs +++ b/src/executor/pop.rs @@ -54,15 +54,13 @@ impl ExecutorPop { let pop_terms: Vec<(String, StoreTermHashed)> = lexer.collect(); let iid_terms_hashed: LinkedHashSet = - LinkedHashSet::from_iter( - iid_terms_hashed_vec.iter().map(|value| *value), - ); + LinkedHashSet::from_iter(iid_terms_hashed_vec.iter().copied()); let remaining_terms: LinkedHashSet = iid_terms_hashed .difference(&LinkedHashSet::from_iter( pop_terms.iter().map(|item| item.1), )) - .map(|value| *value) + .copied() .collect(); debug!( @@ -73,7 +71,7 @@ impl ExecutorPop { count_popped = (iid_terms_hashed.len() - remaining_terms.len()) as u32; if count_popped > 0 { - if remaining_terms.len() == 0 { + if remaining_terms.is_empty() { info!("nuke whole bucket for pop executor"); // Flush bucket (batch operation, as it is shared w/ other \ diff --git a/src/executor/push.rs b/src/executor/push.rs index 3e085f19..e64c2432 100644 --- a/src/executor/push.rs +++ b/src/executor/push.rs @@ -17,7 +17,7 @@ use crate::APP_CONF; pub struct ExecutorPush; impl ExecutorPush { - pub fn execute<'a>(store: StoreItem<'a>, mut lexer: TokenLexer<'a>) -> Result<(), ()> { + pub fn execute<'a>(store: StoreItem<'a>, lexer: TokenLexer<'a>) -> Result<(), ()> { if let StoreItem(collection, Some(bucket), Some(object)) = store { // Important: acquire database access read lock, and reference it in context. This \ // prevents the database from being erased while using it in this block. @@ -85,7 +85,7 @@ impl ExecutorPush { kv_action .get_iid_to_terms(iid) .unwrap_or(None) - .unwrap_or(Vec::new()), + .unwrap_or_default(), ); info!( @@ -93,14 +93,14 @@ impl ExecutorPush { iid_terms_hashed ); - while let Some((term, term_hashed)) = lexer.next() { + for (term, term_hashed) in lexer { // Check that term is not already linked to IID if !iid_terms_hashed.contains(&term_hashed) { if let Ok(term_iids) = kv_action.get_term_to_iids(term_hashed) { has_commits = true; // Add IID in first position in list for terms - let mut term_iids = term_iids.unwrap_or(Vec::new()); + let mut term_iids = term_iids.unwrap_or_default(); // Remove IID from list of IIDs to be popped before inserting in \ // first position? diff --git a/src/executor/search.rs b/src/executor/search.rs index 4c26b7db..ddfbd6d8 100644 --- a/src/executor/search.rs +++ b/src/executor/search.rs @@ -21,7 +21,7 @@ impl ExecutorSearch { pub fn execute<'a>( store: StoreItem<'a>, _event_id: QuerySearchID, - mut lexer: TokenLexer<'a>, + lexer: TokenLexer<'a>, limit: QuerySearchLimit, offset: QuerySearchOffset, ) -> Result>, ()> { @@ -47,12 +47,12 @@ impl ExecutorSearch { // all resulting IIDs for each given term. let mut found_iids: LinkedHashSet = LinkedHashSet::new(); - 'lexing: while let Some((term, term_hashed)) = lexer.next() { + 'lexing: for (term, term_hashed) in lexer { let mut iids = LinkedHashSet::from_iter( kv_action .get_term_to_iids(term_hashed) .unwrap_or(None) - .unwrap_or(Vec::new()) + .unwrap_or_default() .into_iter(), ); @@ -136,7 +136,7 @@ impl ExecutorSearch { if found_iids.is_empty() { found_iids = iids; } else { - found_iids = found_iids.intersection(&iids).map(|value| *value).collect(); + found_iids = found_iids.intersection(&iids).copied().collect(); } debug!( diff --git a/src/lexer/stopwords.rs b/src/lexer/stopwords.rs index 76102c57..9e6fae7e 100644 --- a/src/lexer/stopwords.rs +++ b/src/lexer/stopwords.rs @@ -107,7 +107,7 @@ lazy_static! { } fn make<'a>(words: &[&'a str]) -> HashSet<&'a str> { - words.into_iter().map(|word| *word).collect() + words.iter().copied().collect() } impl LexerStopWord { @@ -329,12 +329,12 @@ mod tests { #[test] fn it_detects_stopwords() { - assert_eq!(LexerStopWord::is("the", None), false); - assert_eq!(LexerStopWord::is("the", Some(Lang::Eng)), true); - assert_eq!(LexerStopWord::is("fox", Some(Lang::Eng)), false); - assert_eq!(LexerStopWord::is("bonjour", Some(Lang::Fra)), false); - assert_eq!(LexerStopWord::is("ici", Some(Lang::Fra)), true); - assert_eq!(LexerStopWord::is("adéu", Some(Lang::Cat)), true); + assert!(!LexerStopWord::is("the", None)); + assert!(LexerStopWord::is("the", Some(Lang::Eng))); + assert!(!LexerStopWord::is("fox", Some(Lang::Eng))); + assert!(!LexerStopWord::is("bonjour", Some(Lang::Fra))); + assert!(LexerStopWord::is("ici", Some(Lang::Fra))); + assert!(LexerStopWord::is("adéu", Some(Lang::Cat))); } #[test] diff --git a/src/lexer/token.rs b/src/lexer/token.rs index 3e2c2576..8f54b8b4 100644 --- a/src/lexer/token.rs +++ b/src/lexer/token.rs @@ -273,7 +273,7 @@ impl<'a> Iterator for TokenLexer<'a> { // - Gibberish words are removed (ie. words that may just be junk) \ // - Stop-words are removed fn next(&mut self) -> Option { - while let Some(word) = self.words.next() { + for word in &mut self.words { // Lower-case word // Notice: unfortunately, as Rust is unicode-aware, we need to convert the str slice \ // to a heap-indexed String; as lower-cased characters may change in bit size. diff --git a/src/main.rs b/src/main.rs index 8fcccff4..5cc2c0fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,13 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) +// Rust lints +#![deny(unstable_features, unused_imports, unused_qualifications)] +// Clippy lints +#![deny(clippy::all)] +// I think we should to refac all places when we use new method +// for another structure +#![allow(clippy::new_ret_no_self)] #![cfg_attr(feature = "benchmark", feature(test))] #[macro_use] @@ -32,9 +39,9 @@ use log::LevelFilter; use channel::listen::{ChannelListen, ChannelListenBuilder}; use channel::statistics::ensure_states as ensure_states_channel_statistics; -use config::config::Config; use config::logger::ConfigLogger; use config::reader::ConfigReader; +use config::Config; use store::fst::StoreFSTPool; use store::kv::StoreKVPool; use tasker::runtime::TaskerBuilder; @@ -49,11 +56,11 @@ struct AppArgs { #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -pub static LINE_FEED: &'static str = "\r\n"; +pub static LINE_FEED: &str = "\r\n"; -pub static THREAD_NAME_CHANNEL_MASTER: &'static str = "sonic-channel-master"; -pub static THREAD_NAME_CHANNEL_CLIENT: &'static str = "sonic-channel-client"; -pub static THREAD_NAME_TASKER: &'static str = "sonic-tasker"; +pub static THREAD_NAME_CHANNEL_MASTER: &str = "sonic-channel-master"; +pub static THREAD_NAME_CHANNEL_CLIENT: &str = "sonic-channel-client"; +pub static THREAD_NAME_TASKER: &str = "sonic-tasker"; macro_rules! gen_spawn_managed { ($name:expr, $method:ident, $thread_name:ident, $managed_fn:ident) => { diff --git a/src/query/builder.rs b/src/query/builder.rs index eec6c9c5..49ebe617 100644 --- a/src/query/builder.rs +++ b/src/query/builder.rs @@ -4,8 +4,8 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -use super::query::Query; use super::types::{QueryGenericLang, QuerySearchLimit, QuerySearchOffset}; +use super::Query; use crate::lexer::token::{TokenLexerBuilder, TokenLexerMode}; use crate::store::item::StoreItemBuilder; diff --git a/src/query/mod.rs b/src/query/mod.rs index 3f1a3282..cb1fd2f2 100644 --- a/src/query/mod.rs +++ b/src/query/mod.rs @@ -5,5 +5,30 @@ // License: Mozilla Public License v2.0 (MPL v2.0) pub mod builder; -pub mod query; pub mod types; + +use crate::lexer::token::TokenLexer; +use crate::store::item::StoreItem; +use types::*; + +pub enum Query<'a> { + Search( + StoreItem<'a>, + QuerySearchID<'a>, + TokenLexer<'a>, + QuerySearchLimit, + QuerySearchOffset, + ), + Suggest( + StoreItem<'a>, + QuerySearchID<'a>, + TokenLexer<'a>, + QuerySearchLimit, + ), + Push(StoreItem<'a>, TokenLexer<'a>), + Pop(StoreItem<'a>, TokenLexer<'a>), + Count(StoreItem<'a>), + FlushC(StoreItem<'a>), + FlushB(StoreItem<'a>), + FlushO(StoreItem<'a>), +} diff --git a/src/query/query.rs b/src/query/query.rs deleted file mode 100644 index 743eda35..00000000 --- a/src/query/query.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Sonic -// -// Fast, lightweight and schema-less search backend -// Copyright: 2019, Valerian Saliou -// License: Mozilla Public License v2.0 (MPL v2.0) - -use super::types::*; -use crate::lexer::token::TokenLexer; -use crate::store::item::StoreItem; - -pub enum Query<'a> { - Search( - StoreItem<'a>, - QuerySearchID<'a>, - TokenLexer<'a>, - QuerySearchLimit, - QuerySearchOffset, - ), - Suggest( - StoreItem<'a>, - QuerySearchID<'a>, - TokenLexer<'a>, - QuerySearchLimit, - ), - Push(StoreItem<'a>, TokenLexer<'a>), - Pop(StoreItem<'a>, TokenLexer<'a>), - Count(StoreItem<'a>), - FlushC(StoreItem<'a>), - FlushB(StoreItem<'a>), - FlushO(StoreItem<'a>), -} diff --git a/src/query/types.rs b/src/query/types.rs index 9d3aa1ed..65ca91fa 100644 --- a/src/query/types.rs +++ b/src/query/types.rs @@ -21,7 +21,7 @@ impl QueryGenericLang { if value == "none" { Some(QueryGenericLang::Disabled) } else { - Lang::from_code(value).map(|lang| QueryGenericLang::Enabled(lang)) + Lang::from_code(value).map(QueryGenericLang::Enabled) } } } diff --git a/src/stopwords/afr.rs b/src/stopwords/afr.rs index b5be005a..aa5025f4 100644 --- a/src/stopwords/afr.rs +++ b/src/stopwords/afr.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_AFR: &[&'static str] = &[ +pub static STOPWORDS_AFR: &[&str] = &[ "'n", "aan", "af", "al", "as", "baie", "by", "daar", "dag", "dat", "die", "dit", "een", "ek", "en", "gaan", "gesê", "haar", "het", "hom", "hulle", "hy", "in", "is", "jou", "jy", "kan", "kom", "ma", "maar", "met", "my", "na", "nie", "om", "ons", "op", "saam", "sal", "se", "sien", diff --git a/src/stopwords/aka.rs b/src/stopwords/aka.rs index 421b1856..4a68c1ab 100644 --- a/src/stopwords/aka.rs +++ b/src/stopwords/aka.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_AKA: &[&'static str] = &[]; +pub static STOPWORDS_AKA: &[&str] = &[]; diff --git a/src/stopwords/amh.rs b/src/stopwords/amh.rs index ecb4239c..f0a2a731 100644 --- a/src/stopwords/amh.rs +++ b/src/stopwords/amh.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_AMH: &[&'static str] = &[]; +pub static STOPWORDS_AMH: &[&str] = &[]; diff --git a/src/stopwords/ara.rs b/src/stopwords/ara.rs index 869f8e63..08d56196 100644 --- a/src/stopwords/ara.rs +++ b/src/stopwords/ara.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_ARA: &[&'static str] = &[ +pub static STOPWORDS_ARA: &[&str] = &[ "،", "آض", "آمينَ", diff --git a/src/stopwords/aze.rs b/src/stopwords/aze.rs index b796697d..c5dba4c8 100644 --- a/src/stopwords/aze.rs +++ b/src/stopwords/aze.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_AZE: &[&'static str] = &[ +pub static STOPWORDS_AZE: &[&str] = &[ "a", "ad", "altı", diff --git a/src/stopwords/bel.rs b/src/stopwords/bel.rs index 620e27fb..1ee1924d 100644 --- a/src/stopwords/bel.rs +++ b/src/stopwords/bel.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_BEL: &[&'static str] = &[]; +pub static STOPWORDS_BEL: &[&str] = &[]; diff --git a/src/stopwords/ben.rs b/src/stopwords/ben.rs index 81f95113..cb936bef 100644 --- a/src/stopwords/ben.rs +++ b/src/stopwords/ben.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_BEN: &[&'static str] = &[ +pub static STOPWORDS_BEN: &[&str] = &[ "অতএব", "অথচ", "অথবা", diff --git a/src/stopwords/bul.rs b/src/stopwords/bul.rs index e15b3f90..8abe1356 100644 --- a/src/stopwords/bul.rs +++ b/src/stopwords/bul.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_BUL: &[&'static str] = &[ +pub static STOPWORDS_BUL: &[&str] = &[ "ð°", "ð°ð²ñ‚ðµð½ñ‚ð¸ñ‡ðµð½", "ð°ð·", diff --git a/src/stopwords/cat.rs b/src/stopwords/cat.rs index 50584d5b..d96107ee 100644 --- a/src/stopwords/cat.rs +++ b/src/stopwords/cat.rs @@ -7,7 +7,7 @@ // Stopwords list's original author: Lluís de Yzaguirre i Maura, Laboratori de Tecnologies \ // Lingüístiques de l'IULA-UPF (Institut de Lingüística Aplicada de la Universitat Pompeu Fabra) -pub static STOPWORDS_CAT: &[&'static str] = &[ +pub static STOPWORDS_CAT: &[&str] = &[ "a", "abans", "abans-d'ahir", diff --git a/src/stopwords/ces.rs b/src/stopwords/ces.rs index e080ed2f..fa7f2118 100644 --- a/src/stopwords/ces.rs +++ b/src/stopwords/ces.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_CES: &[&'static str] = &[ +pub static STOPWORDS_CES: &[&str] = &[ "a", "aby", "ahoj", @@ -25,7 +25,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "až", "bez", "beze", - "blã­zko", + "blã\u{AD}zko", "blízko", "bohuå¾el", "bohužel", @@ -56,8 +56,8 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "chceå¡", "chceš", "chci", - "chtã­t", - "chtä›jã­", + "chtã\u{AD}t", + "chtä›jã\u{AD}", "chtít", "chtějí", "chut'", @@ -124,7 +124,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "jej", "jeji", "jejich", - "jejã­", + "jejã\u{AD}", "její", "jelikož", "jemu", @@ -155,8 +155,8 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "jste", "já", "jã¡", - "jã­", - "jã­m", + "jã\u{AD}", + "jã\u{AD}m", "jí", "jím", "jíž", @@ -185,14 +185,14 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "kterã½", "které", "který", - "kteå™ã­", + "kteå™ã\u{AD}", "kteři", "kteří", "ku", "kvå¯li", "kvůli", "ma", - "majã­", + "majã\u{AD}", "mají", "mate", "me", @@ -211,7 +211,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "moå¾nã¡", "možná", "muj", - "musã­", + "musã\u{AD}", "musí", "muze", "my", @@ -228,8 +228,8 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "mã¡te", "mã¡å¡", "mã©", - "mã­", - "mã­t", + "mã\u{AD}", + "mã\u{AD}t", "mä›", "må¯j", "må¯å¾e", @@ -260,7 +260,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "nebyli", "nebyly", "nechť", - "nedä›lajã­", + "nedä›lajã\u{AD}", "nedä›lã¡", "nedä›lã¡m", "nedä›lã¡me", @@ -275,7 +275,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "neg", "nejsi", "nejsou", - "nemajã­", + "nemajã\u{AD}", "nemají", "nemáme", "nemáte", @@ -284,11 +284,11 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "nemä›l", "neměl", "neni", - "nenã­", + "nenã\u{AD}", "není", - "nestaäã­", + "nestaäã\u{AD}", "nestačí", - "nevadã­", + "nevadã\u{AD}", "nevadí", "nez", "neå¾", @@ -310,7 +310,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "nã¡mi", "nã¡s", "nã¡å¡", - "nã­m", + "nã\u{AD}m", "nä›", "nä›co", "nä›jak", @@ -359,7 +359,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "proc", "prostä›", "prostě", - "prosã­m", + "prosã\u{AD}m", "prosím", "proti", "proto", @@ -394,8 +394,8 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "si", "sice", "skoro", - "smã­", - "smä›jã­", + "smã\u{AD}", + "smä›jã\u{AD}", "smí", "smějí", "snad", @@ -441,8 +441,8 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "tim", "timto", "tipy", - "tisã­c", - "tisã­ce", + "tisã\u{AD}c", + "tisã\u{AD}ce", "tisíc", "tisíce", "to", @@ -528,7 +528,7 @@ pub static STOPWORDS_CES: &[&'static str] = &[ "vždy", "z", "za", - "zatã­mco", + "zatã\u{AD}mco", "zatímco", "zaä", "zač", diff --git a/src/stopwords/cmn.rs b/src/stopwords/cmn.rs index bc325def..b09b6807 100644 --- a/src/stopwords/cmn.rs +++ b/src/stopwords/cmn.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_CMN: &[&'static str] = &[ +pub static STOPWORDS_CMN: &[&str] = &[ "、", "。", "〈", diff --git a/src/stopwords/dan.rs b/src/stopwords/dan.rs index e98a1d85..12e38062 100644 --- a/src/stopwords/dan.rs +++ b/src/stopwords/dan.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_DAN: &[&'static str] = &[ +pub static STOPWORDS_DAN: &[&str] = &[ "ad", "af", "aldrig", "alle", "alt", "anden", "andet", "andre", "at", "bare", "begge", "blev", "blive", "bliver", "da", "de", "dem", "den", "denne", "der", "deres", "det", "dette", "dig", "din", "dine", "disse", "dit", "dog", "du", "efter", "ej", "eller", "en", "end", "ene", diff --git a/src/stopwords/deu.rs b/src/stopwords/deu.rs index 80c950c8..5e69fcf9 100644 --- a/src/stopwords/deu.rs +++ b/src/stopwords/deu.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_DEU: &[&'static str] = &[ +pub static STOPWORDS_DEU: &[&str] = &[ "a", "ab", "aber", diff --git a/src/stopwords/ell.rs b/src/stopwords/ell.rs index 9a288944..7fd325d7 100644 --- a/src/stopwords/ell.rs +++ b/src/stopwords/ell.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_ELL: &[&'static str] = &[ +pub static STOPWORDS_ELL: &[&str] = &[ "αλλα", "αν", "αντι", diff --git a/src/stopwords/eng.rs b/src/stopwords/eng.rs index 84707ae6..88d5bf2e 100644 --- a/src/stopwords/eng.rs +++ b/src/stopwords/eng.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_ENG: &[&'static str] = &[ +pub static STOPWORDS_ENG: &[&str] = &[ "'ll", "'tis", "'twas", diff --git a/src/stopwords/epo.rs b/src/stopwords/epo.rs index 2ca3f61f..ea4cd724 100644 --- a/src/stopwords/epo.rs +++ b/src/stopwords/epo.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_EPO: &[&'static str] = &[ +pub static STOPWORDS_EPO: &[&str] = &[ "adiaŭ", "ajn", "al", diff --git a/src/stopwords/est.rs b/src/stopwords/est.rs index 0ee718d8..a600047b 100644 --- a/src/stopwords/est.rs +++ b/src/stopwords/est.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_EST: &[&'static str] = &[ +pub static STOPWORDS_EST: &[&str] = &[ "aga", "ei", "et", "ja", "jah", "kas", "kui", "kõik", "ma", "me", "mida", "midagi", "mind", "minu", "mis", "mu", "mul", "mulle", "nad", "nii", "oled", "olen", "oli", "oma", "on", "pole", "sa", "seda", "see", "selle", "siin", "siis", "ta", "te", "ära", diff --git a/src/stopwords/fin.rs b/src/stopwords/fin.rs index fbb62575..8cc3f038 100644 --- a/src/stopwords/fin.rs +++ b/src/stopwords/fin.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_FIN: &[&'static str] = &[ +pub static STOPWORDS_FIN: &[&str] = &[ "aiemmin", "aika", "aikaa", diff --git a/src/stopwords/fra.rs b/src/stopwords/fra.rs index 6009f2b2..075c202e 100644 --- a/src/stopwords/fra.rs +++ b/src/stopwords/fra.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_FRA: &[&'static str] = &[ +pub static STOPWORDS_FRA: &[&str] = &[ "a", "abord", "absolument", diff --git a/src/stopwords/guj.rs b/src/stopwords/guj.rs index 058861fb..ea69d2cc 100644 --- a/src/stopwords/guj.rs +++ b/src/stopwords/guj.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_GUJ: &[&'static str] = &[]; +pub static STOPWORDS_GUJ: &[&str] = &[]; diff --git a/src/stopwords/heb.rs b/src/stopwords/heb.rs index 98931f9d..4b5c827f 100644 --- a/src/stopwords/heb.rs +++ b/src/stopwords/heb.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_HEB: &[&'static str] = &[ +pub static STOPWORDS_HEB: &[&str] = &[ "אבל", "או", "אולי", diff --git a/src/stopwords/hin.rs b/src/stopwords/hin.rs index 98957d95..f59782b7 100644 --- a/src/stopwords/hin.rs +++ b/src/stopwords/hin.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_HIN: &[&'static str] = &[ +pub static STOPWORDS_HIN: &[&str] = &[ "अंदर", "अत", "अदि", diff --git a/src/stopwords/hrv.rs b/src/stopwords/hrv.rs index 30de4296..d6612a40 100644 --- a/src/stopwords/hrv.rs +++ b/src/stopwords/hrv.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_HRV: &[&'static str] = &[ +pub static STOPWORDS_HRV: &[&str] = &[ "a", "ako", "ali", "bi", "bih", "bila", "bili", "bilo", "bio", "bismo", "biste", "biti", "bumo", "da", "do", "duž", "ga", "hoće", "hoćemo", "hoćete", "hoćeš", "hoću", "i", "iako", "ih", "ili", "iz", "ja", "je", "jedna", "jedne", "jedno", "jer", "jesam", "jesi", "jesmo", diff --git a/src/stopwords/hun.rs b/src/stopwords/hun.rs index 9f00618d..58af3241 100644 --- a/src/stopwords/hun.rs +++ b/src/stopwords/hun.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_HUN: &[&'static str] = &[ +pub static STOPWORDS_HUN: &[&str] = &[ "a", "abba", "abban", @@ -67,7 +67,7 @@ pub static STOPWORDS_HUN: &[&'static str] = &[ "amit", "amolyan", "amott", - "amã­g", + "amã\u{AD}g", "amíg", "annak", "annál", @@ -726,7 +726,7 @@ pub static STOPWORDS_HUN: &[&'static str] = &[ "mã¡st", "mã©g", "mã©gis", - "mã­g", + "mã\u{AD}g", "mã¶gã©", "mã¶gã©d", "mã¶gã©jã¼k", @@ -917,9 +917,9 @@ pub static STOPWORDS_HUN: &[&'static str] = &[ "szã¡zadik", "szã¡zat", "szã©pen", - "szã­ves", - "szã­vesen", - "szã­veskedjã©k", + "szã\u{AD}ves", + "szã\u{AD}vesen", + "szã\u{AD}veskedjã©k", "szépen", "szét", "szíves", @@ -973,7 +973,7 @@ pub static STOPWORDS_HUN: &[&'static str] = &[ "tã¡vol", "tã©ged", "tã©nyleg", - "tã­z", + "tã\u{AD}z", "tã¶bb", "tã¶bbi", "tã¶bbszã¶r", @@ -1079,7 +1079,7 @@ pub static STOPWORDS_HUN: &[&'static str] = &[ "ã©ves", "ã©vi", "ã©vvel", - "ã­gy", + "ã\u{AD}gy", "ã³ta", "ã¶n", "ã¶nbe", diff --git a/src/stopwords/ind.rs b/src/stopwords/ind.rs index fdc6f6c7..59b6288d 100644 --- a/src/stopwords/ind.rs +++ b/src/stopwords/ind.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_IND: &[&'static str] = &[ +pub static STOPWORDS_IND: &[&str] = &[ "ada", "adalah", "adanya", diff --git a/src/stopwords/ita.rs b/src/stopwords/ita.rs index 2b296350..5715dd1e 100644 --- a/src/stopwords/ita.rs +++ b/src/stopwords/ita.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_ITA: &[&'static str] = &[ +pub static STOPWORDS_ITA: &[&str] = &[ "a", "abbastanza", "abbia", diff --git a/src/stopwords/jav.rs b/src/stopwords/jav.rs index 48c7c1e6..31647c67 100644 --- a/src/stopwords/jav.rs +++ b/src/stopwords/jav.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_JAV: &[&'static str] = &[]; +pub static STOPWORDS_JAV: &[&str] = &[]; diff --git a/src/stopwords/jpn.rs b/src/stopwords/jpn.rs index 931fe18d..c8145e5c 100644 --- a/src/stopwords/jpn.rs +++ b/src/stopwords/jpn.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_JPN: &[&'static str] = &[ +pub static STOPWORDS_JPN: &[&str] = &[ "あそこ", "あっ", "あの", diff --git a/src/stopwords/kan.rs b/src/stopwords/kan.rs index d1b0bb56..22c0af5b 100644 --- a/src/stopwords/kan.rs +++ b/src/stopwords/kan.rs @@ -5,7 +5,7 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_KAN: &[&'static str] = &[ +pub static STOPWORDS_KAN: &[&str] = &[ "ಆ", "ಈ", "ಅಥವಾ", diff --git a/src/stopwords/kat.rs b/src/stopwords/kat.rs index 371e31d6..54fec5d1 100644 --- a/src/stopwords/kat.rs +++ b/src/stopwords/kat.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_KAT: &[&'static str] = &[]; +pub static STOPWORDS_KAT: &[&str] = &[]; diff --git a/src/stopwords/khm.rs b/src/stopwords/khm.rs index 0abf22ff..bb2a930b 100644 --- a/src/stopwords/khm.rs +++ b/src/stopwords/khm.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_KHM: &[&'static str] = &[ +pub static STOPWORDS_KHM: &[&str] = &[ "ៗ", "។ល។", "៚", diff --git a/src/stopwords/kor.rs b/src/stopwords/kor.rs index 27b330f0..a64beabe 100644 --- a/src/stopwords/kor.rs +++ b/src/stopwords/kor.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_KOR: &[&'static str] = &[ +pub static STOPWORDS_KOR: &[&str] = &[ "!", "\"", "$", diff --git a/src/stopwords/lat.rs b/src/stopwords/lat.rs index 34bffdd8..4c2e88b0 100644 --- a/src/stopwords/lat.rs +++ b/src/stopwords/lat.rs @@ -5,7 +5,7 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_LAT: &[&'static str] = &[ +pub static STOPWORDS_LAT: &[&str] = &[ "a", "ab", "ac", "ad", "at", "atque", "aut", "autem", "cum", "de", "dum", "e", "erant", "erat", "est", "et", "etiam", "ex", "haec", "hic", "hoc", "in", "ita", "me", "nec", "neque", "non", "per", "qua", "quae", "quam", "qui", "quibus", "quidem", "quo", "quod", "re", "rebus", "rem", diff --git a/src/stopwords/lav.rs b/src/stopwords/lav.rs index ed7be677..3732e145 100644 --- a/src/stopwords/lav.rs +++ b/src/stopwords/lav.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_LAV: &[&'static str] = &[ +pub static STOPWORDS_LAV: &[&str] = &[ "aiz", "ap", "apakš", diff --git a/src/stopwords/lit.rs b/src/stopwords/lit.rs index 89033eb0..6b4aed13 100644 --- a/src/stopwords/lit.rs +++ b/src/stopwords/lit.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_LIT: &[&'static str] = &[ +pub static STOPWORDS_LIT: &[&str] = &[ "abi", "abidvi", "abiejose", diff --git a/src/stopwords/mal.rs b/src/stopwords/mal.rs index b936abc3..5eaf288a 100644 --- a/src/stopwords/mal.rs +++ b/src/stopwords/mal.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_MAL: &[&'static str] = &[]; +pub static STOPWORDS_MAL: &[&str] = &[]; diff --git a/src/stopwords/mar.rs b/src/stopwords/mar.rs index b3b29b2e..f78626b5 100644 --- a/src/stopwords/mar.rs +++ b/src/stopwords/mar.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_MAR: &[&'static str] = &[ +pub static STOPWORDS_MAR: &[&str] = &[ "अधिक", "अनेक", "अशी", diff --git a/src/stopwords/mkd.rs b/src/stopwords/mkd.rs index 465458b9..62c3b2d1 100644 --- a/src/stopwords/mkd.rs +++ b/src/stopwords/mkd.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_MKD: &[&'static str] = &[]; +pub static STOPWORDS_MKD: &[&str] = &[]; diff --git a/src/stopwords/mya.rs b/src/stopwords/mya.rs index 7e647e25..f8d72b26 100644 --- a/src/stopwords/mya.rs +++ b/src/stopwords/mya.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_MYA: &[&'static str] = &[ +pub static STOPWORDS_MYA: &[&str] = &[ "အပေါ်", "အနက်", "အမြဲတမ်း", diff --git a/src/stopwords/nep.rs b/src/stopwords/nep.rs index 2027f8b8..bd9ab194 100644 --- a/src/stopwords/nep.rs +++ b/src/stopwords/nep.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_NEP: &[&'static str] = &[ +pub static STOPWORDS_NEP: &[&str] = &[ "छ", "र", "पनि", diff --git a/src/stopwords/nld.rs b/src/stopwords/nld.rs index 0f40d4d6..22217171 100644 --- a/src/stopwords/nld.rs +++ b/src/stopwords/nld.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_NLD: &[&'static str] = &[ +pub static STOPWORDS_NLD: &[&str] = &[ "aan", "aangaande", "aangezien", diff --git a/src/stopwords/nob.rs b/src/stopwords/nob.rs index e231cc50..8845ba3e 100644 --- a/src/stopwords/nob.rs +++ b/src/stopwords/nob.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_NOB: &[&'static str] = &[ +pub static STOPWORDS_NOB: &[&str] = &[ "alle", "andre", "at", diff --git a/src/stopwords/ori.rs b/src/stopwords/ori.rs index 7971b4bc..40f36e65 100644 --- a/src/stopwords/ori.rs +++ b/src/stopwords/ori.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_ORI: &[&'static str] = &[]; +pub static STOPWORDS_ORI: &[&str] = &[]; diff --git a/src/stopwords/pan.rs b/src/stopwords/pan.rs index 8275d990..3f647656 100644 --- a/src/stopwords/pan.rs +++ b/src/stopwords/pan.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_PAN: &[&'static str] = &[ +pub static STOPWORDS_PAN: &[&str] = &[ "ਦੇ", "0", "ਵਿੱਚ", diff --git a/src/stopwords/pes.rs b/src/stopwords/pes.rs index bc67a6fb..b6ec3e11 100644 --- a/src/stopwords/pes.rs +++ b/src/stopwords/pes.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_PES: &[&'static str] = &[ +pub static STOPWORDS_PES: &[&str] = &[ "!", ",", ".", diff --git a/src/stopwords/pol.rs b/src/stopwords/pol.rs index d79aa5da..d75d17fc 100644 --- a/src/stopwords/pol.rs +++ b/src/stopwords/pol.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_POL: &[&'static str] = &[ +pub static STOPWORDS_POL: &[&str] = &[ "a", "aby", "ach", diff --git a/src/stopwords/por.rs b/src/stopwords/por.rs index f1b8b099..d24e1d7a 100644 --- a/src/stopwords/por.rs +++ b/src/stopwords/por.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_POR: &[&'static str] = &[ +pub static STOPWORDS_POR: &[&str] = &[ "a", "acerca", "adeus", diff --git a/src/stopwords/ron.rs b/src/stopwords/ron.rs index a471ff03..867ec032 100644 --- a/src/stopwords/ron.rs +++ b/src/stopwords/ron.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_RON: &[&'static str] = &[ +pub static STOPWORDS_RON: &[&str] = &[ "a", "abia", "acea", diff --git a/src/stopwords/rus.rs b/src/stopwords/rus.rs index 53f414b2..57d0c98f 100644 --- a/src/stopwords/rus.rs +++ b/src/stopwords/rus.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_RUS: &[&'static str] = &[ +pub static STOPWORDS_RUS: &[&str] = &[ "c", "а", "алло", diff --git a/src/stopwords/sin.rs b/src/stopwords/sin.rs index ad8dea50..490b7421 100644 --- a/src/stopwords/sin.rs +++ b/src/stopwords/sin.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_SIN: &[&'static str] = &[]; +pub static STOPWORDS_SIN: &[&str] = &[]; diff --git a/src/stopwords/slk.rs b/src/stopwords/slk.rs index c31dd42d..fb0e8960 100644 --- a/src/stopwords/slk.rs +++ b/src/stopwords/slk.rs @@ -4,7 +4,7 @@ // Copyright: 2020, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_SLK: &[&'static str] = &[ +pub static STOPWORDS_SLK: &[&str] = &[ "a", "aby", "aj", diff --git a/src/stopwords/slv.rs b/src/stopwords/slv.rs index 731a643e..77cc2d4a 100644 --- a/src/stopwords/slv.rs +++ b/src/stopwords/slv.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_SLV: &[&'static str] = &[ +pub static STOPWORDS_SLV: &[&str] = &[ "a", "ali", "april", diff --git a/src/stopwords/sna.rs b/src/stopwords/sna.rs index 2ced59a4..7789171d 100644 --- a/src/stopwords/sna.rs +++ b/src/stopwords/sna.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_SNA: &[&'static str] = &[]; +pub static STOPWORDS_SNA: &[&str] = &[]; diff --git a/src/stopwords/spa.rs b/src/stopwords/spa.rs index 8bb200ad..3c4f2411 100644 --- a/src/stopwords/spa.rs +++ b/src/stopwords/spa.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_SPA: &[&'static str] = &[ +pub static STOPWORDS_SPA: &[&str] = &[ "0", "1", "2", diff --git a/src/stopwords/srp.rs b/src/stopwords/srp.rs index e74e32a5..3bee4c19 100644 --- a/src/stopwords/srp.rs +++ b/src/stopwords/srp.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_SRP: &[&'static str] = &[]; +pub static STOPWORDS_SRP: &[&str] = &[]; diff --git a/src/stopwords/swe.rs b/src/stopwords/swe.rs index 93002090..c02eab28 100644 --- a/src/stopwords/swe.rs +++ b/src/stopwords/swe.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_SWE: &[&'static str] = &[ +pub static STOPWORDS_SWE: &[&str] = &[ "aderton", "adertonde", "adjö", diff --git a/src/stopwords/tam.rs b/src/stopwords/tam.rs index aa512574..9390154c 100644 --- a/src/stopwords/tam.rs +++ b/src/stopwords/tam.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_TAM: &[&'static str] = &[ +pub static STOPWORDS_TAM: &[&str] = &[ "ஒரு", "என்று", "மற்றும்", diff --git a/src/stopwords/tel.rs b/src/stopwords/tel.rs index 65820a82..2c6209e0 100644 --- a/src/stopwords/tel.rs +++ b/src/stopwords/tel.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_TEL: &[&'static str] = &[]; +pub static STOPWORDS_TEL: &[&str] = &[]; diff --git a/src/stopwords/tha.rs b/src/stopwords/tha.rs index cc836cec..1fcee6e0 100644 --- a/src/stopwords/tha.rs +++ b/src/stopwords/tha.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_THA: &[&'static str] = &[ +pub static STOPWORDS_THA: &[&str] = &[ "กล่าว", "กว่า", "กัน", diff --git a/src/stopwords/tuk.rs b/src/stopwords/tuk.rs index 0ba57440..d0c87b4c 100644 --- a/src/stopwords/tuk.rs +++ b/src/stopwords/tuk.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_TUK: &[&'static str] = &[]; +pub static STOPWORDS_TUK: &[&str] = &[]; diff --git a/src/stopwords/tur.rs b/src/stopwords/tur.rs index c3b2c6a1..d0d023dd 100644 --- a/src/stopwords/tur.rs +++ b/src/stopwords/tur.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_TUR: &[&'static str] = &[ +pub static STOPWORDS_TUR: &[&str] = &[ "acaba", "acep", "adamakıllı", diff --git a/src/stopwords/ukr.rs b/src/stopwords/ukr.rs index 05774d73..bc17e9e7 100644 --- a/src/stopwords/ukr.rs +++ b/src/stopwords/ukr.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_UKR: &[&'static str] = &[ +pub static STOPWORDS_UKR: &[&str] = &[ "але", "ви", "вона", diff --git a/src/stopwords/urd.rs b/src/stopwords/urd.rs index 70b7ab71..f72a16f0 100644 --- a/src/stopwords/urd.rs +++ b/src/stopwords/urd.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_URD: &[&'static str] = &[ +pub static STOPWORDS_URD: &[&str] = &[ "آئی", "آئے", "آج", diff --git a/src/stopwords/uzb.rs b/src/stopwords/uzb.rs index 0a10c139..14112d47 100644 --- a/src/stopwords/uzb.rs +++ b/src/stopwords/uzb.rs @@ -5,4 +5,4 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // Notice: we do not have stopwords for this language yet. -pub static STOPWORDS_UZB: &[&'static str] = &[]; +pub static STOPWORDS_UZB: &[&str] = &[]; diff --git a/src/stopwords/vie.rs b/src/stopwords/vie.rs index fc893c3c..6b9c6375 100644 --- a/src/stopwords/vie.rs +++ b/src/stopwords/vie.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_VIE: &[&'static str] = &[ +pub static STOPWORDS_VIE: &[&str] = &[ "a ha", "a-lô", "ai", diff --git a/src/stopwords/yid.rs b/src/stopwords/yid.rs index c3ec9d10..ab678894 100644 --- a/src/stopwords/yid.rs +++ b/src/stopwords/yid.rs @@ -5,7 +5,7 @@ // License: Mozilla Public License v2.0 (MPL v2.0) // This is an alias for HEB stopwords, but I may be mistaken there. -pub static STOPWORDS_YID: &[&'static str] = &[ +pub static STOPWORDS_YID: &[&str] = &[ "אבל", "או", "אולי", diff --git a/src/stopwords/zul.rs b/src/stopwords/zul.rs index a04c1f88..e12e8d6c 100644 --- a/src/stopwords/zul.rs +++ b/src/stopwords/zul.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -pub static STOPWORDS_ZUL: &[&'static str] = &[ +pub static STOPWORDS_ZUL: &[&str] = &[ "futhi", "kahle", "kakhulu", diff --git a/src/store/fst.rs b/src/store/fst.rs index 51cc638c..64cb42a4 100644 --- a/src/store/fst.rs +++ b/src/store/fst.rs @@ -78,8 +78,8 @@ const ATOM_HASH_RADIX: usize = 16; lazy_static! { pub static ref GRAPH_ACCESS_LOCK: Arc> = Arc::new(RwLock::new(false)); - static ref GRAPH_ACQUIRE_LOCK: Arc> = Arc::new(Mutex::new(false)); - static ref GRAPH_REBUILD_LOCK: Arc> = Arc::new(Mutex::new(false)); + static ref GRAPH_ACQUIRE_LOCK: Arc> = Arc::new(Mutex::new(())); + static ref GRAPH_REBUILD_LOCK: Arc> = Arc::new(Mutex::new(())); static ref GRAPH_POOL: Arc>> = Arc::new(RwLock::new(HashMap::new())); static ref GRAPH_CONSOLIDATE: Arc>> = @@ -203,7 +203,7 @@ impl StoreFSTPool { ); for key in &*graph_consolidate_read { - if let Some(store) = graph_pool_read.get(&key) { + if let Some(store) = graph_pool_read.get(key) { let not_consolidated_for = store .last_consolidated .read() @@ -321,50 +321,43 @@ impl StoreFSTPool { let collection = collection?; // Actual collection found? - match (collection.file_type(), collection.file_name().to_str()) { - (Ok(collection_file_type), Some(collection_name)) => { - if collection_file_type.is_dir() { - debug!("fst collection ongoing {}: {}", action, collection_name); - - // Create write folder for collection - fs::create_dir_all(write_path.join(collection_name))?; - - // Iterate on FST collection buckets - for bucket in fs::read_dir(read_path.join(collection_name))? { - let bucket = bucket?; - - // Actual bucket found? - match (bucket.file_type(), bucket.file_name().to_str()) { - (Ok(bucket_file_type), Some(bucket_file_name)) => { - let bucket_file_name_len = bucket_file_name.len(); - - if bucket_file_type.is_file() - && bucket_file_name_len > fst_extension_len - && bucket_file_name.ends_with(fst_extension) - { - // Acquire bucket name (from full file name) - let bucket_name = &bucket_file_name - [..(bucket_file_name_len - fst_extension_len)]; - - debug!( - "fst bucket ongoing {}: {}/{}", - action, collection_name, bucket_name - ); - - fn_item( - write_path, - &bucket.path(), - collection_name, - bucket_name, - )?; - } - } - _ => {} + if let (Ok(collection_file_type), Some(collection_name)) = + (collection.file_type(), collection.file_name().to_str()) + { + if collection_file_type.is_dir() { + debug!("fst collection ongoing {}: {}", action, collection_name); + + // Create write folder for collection + fs::create_dir_all(write_path.join(collection_name))?; + + // Iterate on FST collection buckets + for bucket in fs::read_dir(read_path.join(collection_name))? { + let bucket = bucket?; + + // Actual bucket found? + if let (Ok(bucket_file_type), Some(bucket_file_name)) = + (bucket.file_type(), bucket.file_name().to_str()) + { + let bucket_file_name_len = bucket_file_name.len(); + + if bucket_file_type.is_file() + && bucket_file_name_len > fst_extension_len + && bucket_file_name.ends_with(fst_extension) + { + // Acquire bucket name (from full file name) + let bucket_name = + &bucket_file_name[..(bucket_file_name_len - fst_extension_len)]; + + debug!( + "fst bucket ongoing {}: {}/{}", + action, collection_name, bucket_name + ); + + fn_item(write_path, &bucket.path(), collection_name, bucket_name)?; } } } } - _ => {} } } @@ -415,7 +408,7 @@ impl StoreFSTPool { collection_hash as StoreFSTAtom, bucket_hash as StoreFSTAtom, ) - .or(io_error!("graph open failure"))?; + .map_err(|_| io_error!("graph open failure"))?; let mut origin_fst_stream = origin_fst.stream(); @@ -423,8 +416,8 @@ impl StoreFSTPool { count_words += 1; // Write word, and append a new line - backup_fst_writer.write(word)?; - backup_fst_writer.write("\n".as_bytes())?; + backup_fst_writer.write_all(word)?; + backup_fst_writer.write_all(b"\n")?; } info!( @@ -484,19 +477,19 @@ impl StoreFSTPool { let fst_backup_reader = BufReader::new(File::open(&origin_path)?); let mut fst_builder = FSTSetBuilder::new(fst_writer) - .or(io_error!("graph restore builder failure"))?; + .map_err(|_| io_error!("graph restore builder failure"))?; for word in fst_backup_reader.lines() { let word = word?; fst_builder .insert(word) - .or(io_error!("graph restore word insert failure"))?; + .map_err(|_| io_error!("graph restore word insert failure"))?; } fst_builder .finish() - .or(io_error!("graph restore finish failure"))?; + .map_err(|_| io_error!("graph restore finish failure"))?; info!( "fst bucket: {}/{} restored to path: {:?} from backup: {:?}", @@ -801,10 +794,8 @@ impl StoreGenericBuilder for StoreFSTBuilder { last_consolidated: Arc::new(RwLock::new(now)), } }) - .or_else(|err| { + .map_err(|err| { error!("failed opening fst: {}", err); - - Err(()) }) } } @@ -822,7 +813,7 @@ impl StoreFST { // Regex format: '{escaped_word}([{unicode_range}]*)' let mut regex_str = regex_escape(word); - regex_str.push_str("("); + regex_str.push('('); let write_result = LexerRegexRange::from(word) .unwrap_or_default() @@ -911,7 +902,7 @@ impl StoreFST { } impl StoreGeneric for StoreFST { - fn ref_last_used<'a>(&'a self) -> &'a RwLock { + fn ref_last_used(&self) -> &RwLock { &self.last_used } } @@ -1214,17 +1205,14 @@ impl StoreFSTMisc { let fst_extension = path_mode.extension(); let fst_extension_len = fst_extension.len(); - for entry in entries { - if let Ok(entry) = entry { - if let Some(entry_name) = entry.file_name().to_str() { - let entry_name_len = entry_name.len(); + for entry in entries.flatten() { + if let Some(entry_name) = entry.file_name().to_str() { + let entry_name_len = entry_name.len(); - // FST file found? This is a bucket. - if entry_name_len > fst_extension_len - && entry_name.ends_with(fst_extension) - { - count += 1; - } + // FST file found? This is a bucket. + if entry_name_len > fst_extension_len && entry_name.ends_with(fst_extension) + { + count += 1; } } } @@ -1262,7 +1250,7 @@ impl StoreFSTMisc { } // Not over limit - return false; + false } } diff --git a/src/store/generic.rs b/src/store/generic.rs index acf54ba2..1b42b139 100644 --- a/src/store/generic.rs +++ b/src/store/generic.rs @@ -14,7 +14,7 @@ use std::time::SystemTime; pub trait StoreGenericKey {} pub trait StoreGeneric { - fn ref_last_used<'a>(&'a self) -> &'a RwLock; + fn ref_last_used(&self) -> &RwLock; } pub trait StoreGenericPool< @@ -66,13 +66,13 @@ pub trait StoreGenericPool< Ok(store_box) } - Err(err) => { + Err(_) => { error!( "failed opening {} store for collection: {} (pool key: {})", kind, collection_str, pool_key ); - Err(err) + Err(()) } } } diff --git a/src/store/item.rs b/src/store/item.rs index 0e75b458..01d465be 100644 --- a/src/store/item.rs +++ b/src/store/item.rs @@ -16,6 +16,8 @@ pub struct StoreItem<'a>( #[derive(Copy, Clone, PartialEq, Debug)] pub struct StoreItemPart<'a>(&'a str); +// TODO: Change variant names +#[allow(clippy::enum_variant_names)] #[derive(PartialEq, Debug)] pub enum StoreItemError { InvalidCollection, @@ -30,13 +32,14 @@ impl<'a> StoreItemPart<'a> { pub fn from_str(part: &'a str) -> Result { let len = part.len(); - if len > STORE_ITEM_PART_LEN_MIN && len <= STORE_ITEM_PART_LEN_MAX { - if part.chars().all(|character| character.is_ascii()) { - return Ok(StoreItemPart(part)); - } + if len > STORE_ITEM_PART_LEN_MIN + && len <= STORE_ITEM_PART_LEN_MAX + && part.chars().all(|character| character.is_ascii()) + { + Ok(StoreItemPart(part)) + } else { + Err(()) } - - Err(()) } pub fn as_str(&self) -> &'a str { @@ -44,9 +47,9 @@ impl<'a> StoreItemPart<'a> { } } -impl<'a> Into<&'a str> for StoreItemPart<'a> { - fn into(self) -> &'a str { - self.as_str() +impl<'a> From> for &'a str { + fn from(part: StoreItemPart<'a>) -> Self { + part.as_str() } } diff --git a/src/store/keyer.rs b/src/store/keyer.rs index 2ad1522b..28a613e5 100644 --- a/src/store/keyer.rs +++ b/src/store/keyer.rs @@ -126,6 +126,7 @@ impl StoreKeyer { } impl StoreKeyerHasher { + #![allow(clippy::wrong_self_convention)] pub fn to_compact(part: &str) -> u32 { let mut hasher = XxHash32::with_seed(0); diff --git a/src/store/kv.rs b/src/store/kv.rs index a07e27b9..85f1777b 100644 --- a/src/store/kv.rs +++ b/src/store/kv.rs @@ -68,8 +68,8 @@ const ATOM_HASH_RADIX: usize = 16; lazy_static! { pub static ref STORE_ACCESS_LOCK: Arc> = Arc::new(RwLock::new(false)); - static ref STORE_ACQUIRE_LOCK: Arc> = Arc::new(Mutex::new(false)); - static ref STORE_FLUSH_LOCK: Arc> = Arc::new(Mutex::new(false)); + static ref STORE_ACQUIRE_LOCK: Arc> = Arc::new(Mutex::new(())); + static ref STORE_FLUSH_LOCK: Arc> = Arc::new(Mutex::new(())); static ref STORE_POOL: Arc>> = Arc::new(RwLock::new(HashMap::new())); } @@ -94,8 +94,7 @@ impl StoreKVPool { let store_pool_read = STORE_POOL.read().unwrap(); if let Some(store_kv) = store_pool_read.get(&pool_key) { - Self::proceed_acquire_cache("kv", collection_str, pool_key, store_kv) - .map(|result| Some(result)) + Self::proceed_acquire_cache("kv", collection_str, pool_key, store_kv).map(Some) } else { info!( "kv store not in pool for collection: {} {}, opening it", @@ -117,8 +116,7 @@ impl StoreKVPool { // the database does not exist yet on disk and we are just looking to read data from \ // it) if can_open_db { - Self::proceed_acquire_open("kv", collection_str, pool_key, &*STORE_POOL) - .map(|result| Some(result)) + Self::proceed_acquire_open("kv", collection_str, pool_key, &*STORE_POOL).map(Some) } else { Ok(None) } @@ -253,15 +251,14 @@ impl StoreKVPool { let collection = collection?; // Actual collection found? - match (collection.file_type(), collection.file_name().to_str()) { - (Ok(collection_file_type), Some(collection_name)) => { - if collection_file_type.is_dir() { - debug!("kv collection ongoing {}: {}", action, collection_name); + if let (Ok(collection_file_type), Some(collection_name)) = + (collection.file_type(), collection.file_name().to_str()) + { + if collection_file_type.is_dir() { + debug!("kv collection ongoing {}: {}", action, collection_name); - fn_item(write_path, &collection.path(), collection_name)?; - } + fn_item(write_path, &collection.path(), collection_name)?; } - _ => {} } } @@ -298,17 +295,17 @@ impl StoreKVPool { if let Ok(collection_radix) = RadixNum::from_str(collection_name, ATOM_HASH_RADIX) { if let Ok(collection_hash) = collection_radix.as_decimal() { let origin_kv = StoreKVBuilder::open(collection_hash as StoreKVAtom) - .or(io_error!("database open failure"))?; + .map_err(|_| io_error!("database open failure"))?; // Initialize KV database backup engine let mut kv_backup_engine = DBBackupEngine::open(&DBBackupEngineOptions::default(), &kv_backup_path) - .or(io_error!("backup engine failure"))?; + .map_err(|_| io_error!("backup engine failure"))?; // Proceed actual KV database backup kv_backup_engine .create_new_backup(&origin_kv) - .or(io_error!("database backup failure"))?; + .map_err(|_| io_error!("database backup failure"))?; info!( "kv collection: {} backed up to path: {:?}", @@ -355,11 +352,11 @@ impl StoreKVPool { // Initialize KV database backup engine let mut kv_backup_engine = DBBackupEngine::open(&DBBackupEngineOptions::default(), &origin_path) - .or(io_error!("backup engine failure"))?; + .map_err(|_| io_error!("backup engine failure"))?; kv_backup_engine .restore_from_latest_backup(&kv_path, &kv_path, &DBRestoreOptions::default()) - .or(io_error!("database restore failure"))?; + .map_err(|_| io_error!("database restore failure"))?; info!( "kv collection: {} restored to path: {:?} from backup: {:?}", @@ -460,10 +457,8 @@ impl StoreGenericBuilder for StoreKVBuilder { lock: RwLock::new(false), } }) - .or_else(|err| { + .map_err(|err| { error!("failed opening kv: {}", err); - - Err(()) }) } } @@ -520,7 +515,7 @@ impl StoreKV { } impl StoreGeneric for StoreKV { - fn ref_last_used<'a>(&'a self) -> &'a RwLock { + fn ref_last_used(&self) -> &RwLock { &self.last_used } } @@ -599,7 +594,7 @@ impl<'a> StoreKVAction<'a> { StoreMetaKey::IIDIncr => value .parse::() .ok() - .map(|value| StoreMetaValue::IIDIncr(value)) + .map(StoreMetaValue::IIDIncr) .or(None), } } else { @@ -942,7 +937,7 @@ impl<'a> StoreKVAction<'a> { // Delete OID <> IID association match ( - self.delete_oid_to_iid(&oid), + self.delete_oid_to_iid(oid), self.delete_iid_to_oid(iid), self.delete_iid_to_terms(iid), ) { diff --git a/src/store/macros.rs b/src/store/macros.rs index eb342ebf..179ec4f3 100644 --- a/src/store/macros.rs +++ b/src/store/macros.rs @@ -7,6 +7,6 @@ #[macro_export] macro_rules! io_error { ($error:expr) => { - Err(io::Error::new(io::ErrorKind::Other, $error)) + io::Error::new(io::ErrorKind::Other, $error) }; } diff --git a/src/store/operation.rs b/src/store/operation.rs index 2a9c0830..c2ab237f 100644 --- a/src/store/operation.rs +++ b/src/store/operation.rs @@ -12,7 +12,7 @@ use crate::executor::pop::ExecutorPop; use crate::executor::push::ExecutorPush; use crate::executor::search::ExecutorSearch; use crate::executor::suggest::ExecutorSuggest; -use crate::query::query::Query; +use crate::query::Query; pub struct StoreOperationDispatch;