mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
make clippy happy 1
This commit is contained in:
parent
2019db972d
commit
641d12fb2d
@ -39,7 +39,7 @@ fn prepare_database(path: &Path) -> Database {
|
|||||||
let file = File::open(path).unwrap();
|
let file = File::open(path).unwrap();
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
let settings: Settings = serde_json::from_reader(reader).unwrap();
|
let settings: Settings = serde_json::from_reader(reader).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
db.update_write::<_, _, Box<dyn Error>>(|writer| {
|
db.update_write::<_, _, Box<dyn Error>>(|writer| {
|
||||||
|
@ -123,7 +123,7 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box<dy
|
|||||||
let settings = {
|
let settings = {
|
||||||
let string = fs::read_to_string(&command.settings)?;
|
let string = fs::read_to_string(&command.settings)?;
|
||||||
let settings: Settings = serde_json::from_str(&string).unwrap();
|
let settings: Settings = serde_json::from_str(&string).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
db.update_write(|w| index.settings_update(w, settings))?;
|
db.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
@ -82,8 +82,7 @@ fn update_awaiter(
|
|||||||
update_fn: Arc<ArcSwapFn>,
|
update_fn: Arc<ArcSwapFn>,
|
||||||
index: Index,
|
index: Index,
|
||||||
) -> MResult<()> {
|
) -> MResult<()> {
|
||||||
let mut receiver = receiver.into_iter();
|
for event in receiver {
|
||||||
while let Some(event) = receiver.next() {
|
|
||||||
|
|
||||||
// if we receive a *MustClear* event, clear the index and break the loop
|
// if we receive a *MustClear* event, clear the index and break the loop
|
||||||
if let UpdateEvent::MustClear = event {
|
if let UpdateEvent::MustClear = event {
|
||||||
@ -547,7 +546,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut update_writer = db.update_write_txn().unwrap();
|
let mut update_writer = db.update_write_txn().unwrap();
|
||||||
@ -610,7 +609,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut update_writer = db.update_write_txn().unwrap();
|
let mut update_writer = db.update_write_txn().unwrap();
|
||||||
@ -672,7 +671,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut update_writer = db.update_write_txn().unwrap();
|
let mut update_writer = db.update_write_txn().unwrap();
|
||||||
@ -727,7 +726,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut update_writer = db.update_write_txn().unwrap();
|
let mut update_writer = db.update_write_txn().unwrap();
|
||||||
@ -763,7 +762,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = db.update_write_txn().unwrap();
|
let mut writer = db.update_write_txn().unwrap();
|
||||||
@ -829,7 +828,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = db.update_write_txn().unwrap();
|
let mut writer = db.update_write_txn().unwrap();
|
||||||
@ -871,7 +870,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = db.update_write_txn().unwrap();
|
let mut writer = db.update_write_txn().unwrap();
|
||||||
@ -951,7 +950,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = db.update_write_txn().unwrap();
|
let mut writer = db.update_write_txn().unwrap();
|
||||||
@ -1090,7 +1089,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = db.update_write_txn().unwrap();
|
let mut writer = db.update_write_txn().unwrap();
|
||||||
@ -1166,7 +1165,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
settings.into_update().unwrap()
|
settings.to_update().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = db.update_write_txn().unwrap();
|
let mut writer = db.update_write_txn().unwrap();
|
||||||
|
@ -70,7 +70,7 @@ impl FacetFilter {
|
|||||||
bad_value => return Err(FacetError::unexpected_token(&["Array", "String"], bad_value).into()),
|
bad_value => return Err(FacetError::unexpected_token(&["Array", "String"], bad_value).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(Self(filter));
|
Ok(Self(filter))
|
||||||
}
|
}
|
||||||
bad_value => Err(FacetError::unexpected_token(&["Array"], bad_value).into()),
|
bad_value => Err(FacetError::unexpected_token(&["Array"], bad_value).into()),
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ struct ConditionValue<'a> {
|
|||||||
|
|
||||||
impl<'a> ConditionValue<'a> {
|
impl<'a> ConditionValue<'a> {
|
||||||
pub fn new(value: &Pair<'a, Rule>) -> Self {
|
pub fn new(value: &Pair<'a, Rule>) -> Self {
|
||||||
let value = match value.as_rule() {
|
match value.as_rule() {
|
||||||
Rule::string | Rule::word => {
|
Rule::string | Rule::word => {
|
||||||
let string = value.as_str();
|
let string = value.as_str();
|
||||||
let boolean = match value.as_str() {
|
let boolean = match value.as_str() {
|
||||||
@ -43,12 +43,11 @@ impl<'a> ConditionValue<'a> {
|
|||||||
ConditionValue { string, boolean, number }
|
ConditionValue { string, boolean, number }
|
||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
}
|
||||||
value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
self.string.as_ref()
|
self.string
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_number(&self) -> Option<&Number> {
|
pub fn as_number(&self) -> Option<&Number> {
|
||||||
@ -73,7 +72,7 @@ fn get_field_value<'a>(schema: &Schema, pair: Pair<'a, Rule>) -> Result<(FieldId
|
|||||||
let key = items.next().unwrap();
|
let key = items.next().unwrap();
|
||||||
let field = schema
|
let field = schema
|
||||||
.id(key.as_str())
|
.id(key.as_str())
|
||||||
.ok_or::<PestError<Rule>>(PestError::new_from_span(
|
.ok_or_else(|| PestError::new_from_span(
|
||||||
ErrorVariant::CustomError {
|
ErrorVariant::CustomError {
|
||||||
message: format!(
|
message: format!(
|
||||||
"attribute `{}` not found, available attributes are: {}",
|
"attribute `{}` not found, available attributes are: {}",
|
||||||
|
@ -26,7 +26,7 @@ pub enum Filter<'a> {
|
|||||||
|
|
||||||
impl<'a> Filter<'a> {
|
impl<'a> Filter<'a> {
|
||||||
pub fn parse(expr: &'a str, schema: &'a Schema) -> FilterResult<'a> {
|
pub fn parse(expr: &'a str, schema: &'a Schema) -> FilterResult<'a> {
|
||||||
let mut lexed = FilterParser::parse(Rule::prgm, expr.as_ref())?;
|
let mut lexed = FilterParser::parse(Rule::prgm, expr)?;
|
||||||
Self::build(lexed.next().unwrap().into_inner(), schema)
|
Self::build(lexed.next().unwrap().into_inner(), schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use std::str::FromStr;
|
|||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Hash)]
|
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
|
||||||
pub enum Number {
|
pub enum Number {
|
||||||
Unsigned(u64),
|
Unsigned(u64),
|
||||||
Signed(i64),
|
Signed(i64),
|
||||||
|
@ -53,7 +53,7 @@ impl QueryWordsMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let replacement = replacement[common_left..replacement.len() - common_right].iter().cloned().collect();
|
let replacement = replacement[common_left..replacement.len() - common_right].to_vec();
|
||||||
self.mappings.insert(id + common_left, (range.clone(), replacement));
|
self.mappings.insert(id + common_left, (range.clone(), replacement));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ use self::RankingRule::*;
|
|||||||
pub const DEFAULT_RANKING_RULES: [RankingRule; 6] = [Typo, Words, Proximity, Attribute, WordsPosition, Exactness];
|
pub const DEFAULT_RANKING_RULES: [RankingRule; 6] = [Typo, Words, Proximity, Attribute, WordsPosition, Exactness];
|
||||||
|
|
||||||
static RANKING_RULE_REGEX: Lazy<regex::Regex> = Lazy::new(|| {
|
static RANKING_RULE_REGEX: Lazy<regex::Regex> = Lazy::new(|| {
|
||||||
let regex = regex::Regex::new(r"(asc|desc)\(([a-zA-Z0-9-_]*)\)").unwrap();
|
regex::Regex::new(r"(asc|desc)\(([a-zA-Z0-9-_]*)\)").unwrap()
|
||||||
regex
|
|
||||||
});
|
});
|
||||||
|
|
||||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||||
@ -44,11 +43,11 @@ fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn into_update(&self) -> Result<SettingsUpdate, RankingRuleConversionError> {
|
pub fn to_update(&self) -> Result<SettingsUpdate, RankingRuleConversionError> {
|
||||||
let settings = self.clone();
|
let settings = self.clone();
|
||||||
|
|
||||||
let ranking_rules = match settings.ranking_rules {
|
let ranking_rules = match settings.ranking_rules {
|
||||||
Some(Some(rules)) => UpdateState::Update(RankingRule::from_iter(rules.iter())?),
|
Some(Some(rules)) => UpdateState::Update(RankingRule::try_from_iter(rules.iter())?),
|
||||||
Some(None) => UpdateState::Clear,
|
Some(None) => UpdateState::Clear,
|
||||||
None => UpdateState::Nothing,
|
None => UpdateState::Nothing,
|
||||||
};
|
};
|
||||||
@ -152,7 +151,7 @@ impl RankingRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_iter(rules: impl IntoIterator<Item = impl AsRef<str>>) -> Result<Vec<RankingRule>, RankingRuleConversionError> {
|
pub fn try_from_iter(rules: impl IntoIterator<Item = impl AsRef<str>>) -> Result<Vec<RankingRule>, RankingRuleConversionError> {
|
||||||
rules.into_iter()
|
rules.into_iter()
|
||||||
.map(|s| RankingRule::from_str(s.as_ref()))
|
.map(|s| RankingRule::from_str(s.as_ref()))
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -287,10 +287,10 @@ impl Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn distinct_attribute(&self, reader: &heed::RoTxn<MainT>) -> MResult<Option<FieldId>> {
|
pub fn distinct_attribute(&self, reader: &heed::RoTxn<MainT>) -> MResult<Option<FieldId>> {
|
||||||
if let Some(value) = self.main.get::<_, Str, OwnedType<u16>>(reader, DISTINCT_ATTRIBUTE_KEY)? {
|
match self.main.get::<_, Str, OwnedType<u16>>(reader, DISTINCT_ATTRIBUTE_KEY)? {
|
||||||
return Ok(Some(FieldId(value.to_owned())))
|
Some(value) => Ok(Some(FieldId(value.to_owned()))),
|
||||||
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
return Ok(None)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_distinct_attribute(self, writer: &mut heed::RwTxn<MainT>, value: FieldId) -> MResult<()> {
|
pub fn put_distinct_attribute(self, writer: &mut heed::RwTxn<MainT>, value: FieldId) -> MResult<()> {
|
||||||
|
@ -26,6 +26,7 @@ pub trait ErrorCode: std::error::Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
enum ErrorType {
|
enum ErrorType {
|
||||||
InternalError,
|
InternalError,
|
||||||
InvalidRequestError,
|
InvalidRequestError,
|
||||||
|
@ -45,7 +45,7 @@ async fn update_all(
|
|||||||
let update_id = data.db.update_write::<_, _, ResponseError>(|writer| {
|
let update_id = data.db.update_write::<_, _, ResponseError>(|writer| {
|
||||||
let settings = body
|
let settings = body
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.into_update()
|
.to_update()
|
||||||
.map_err(Error::bad_request)?;
|
.map_err(Error::bad_request)?;
|
||||||
let update_id = index.settings_update(writer, settings)?;
|
let update_id = index.settings_update(writer, settings)?;
|
||||||
Ok(update_id)
|
Ok(update_id)
|
||||||
@ -211,7 +211,7 @@ async fn update_rules(
|
|||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.into_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
@ -282,7 +282,7 @@ async fn update_distinct(
|
|||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.into_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
@ -350,7 +350,7 @@ async fn update_searchable(
|
|||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.into_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
|
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ async fn update_displayed(
|
|||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.into_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
@ -490,7 +490,7 @@ async fn update_accept_new_fields(
|
|||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.into_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
@ -549,7 +549,7 @@ async fn update_attributes_for_faceting(
|
|||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.into_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
|
@ -2,7 +2,7 @@ use crate::{FieldsMap, FieldId, SResult, Error, IndexedPos};
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
||||||
pub struct Schema {
|
pub struct Schema {
|
||||||
fields_map: FieldsMap,
|
fields_map: FieldsMap,
|
||||||
|
|
||||||
@ -19,13 +19,8 @@ pub struct Schema {
|
|||||||
impl Schema {
|
impl Schema {
|
||||||
pub fn new() -> Schema {
|
pub fn new() -> Schema {
|
||||||
Schema {
|
Schema {
|
||||||
fields_map: FieldsMap::default(),
|
|
||||||
primary_key: None,
|
|
||||||
ranked: HashSet::new(),
|
|
||||||
displayed: HashSet::new(),
|
|
||||||
indexed: Vec::new(),
|
|
||||||
indexed_map: HashMap::new(),
|
|
||||||
accept_new_fields: true,
|
accept_new_fields: true,
|
||||||
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user