diff --git a/milli/src/criterion.rs b/milli/src/criterion.rs index 8abfb5a30..4299e4974 100644 --- a/milli/src/criterion.rs +++ b/milli/src/criterion.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use crate::error::Error; -use crate::{AscDesc, AscDescError, Member, UserError}; +use crate::{AscDesc, Member, UserError}; #[derive(Debug)] pub enum CriterionError { @@ -41,6 +41,12 @@ impl fmt::Display for CriterionError { } } +impl From for Error { + fn from(error: CriterionError) -> Self { + Self::UserError(UserError::CriterionError(error)) + } +} + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] pub enum Criterion { /// Sorted by decreasing number of matched query terms. @@ -85,35 +91,17 @@ impl FromStr for Criterion { "attribute" => Ok(Criterion::Attribute), "sort" => Ok(Criterion::Sort), "exactness" => Ok(Criterion::Exactness), - text => match AscDesc::from_str(text) { - Ok(AscDesc::Asc(Member::Field(field))) => Ok(Criterion::Asc(field)), - Ok(AscDesc::Desc(Member::Field(field))) => Ok(Criterion::Desc(field)), - Ok(AscDesc::Asc(Member::Geo(_))) | Ok(AscDesc::Desc(Member::Geo(_))) => { + text => match AscDesc::from_str(text)? { + AscDesc::Asc(Member::Field(field)) => Ok(Criterion::Asc(field)), + AscDesc::Desc(Member::Field(field)) => Ok(Criterion::Desc(field)), + AscDesc::Asc(Member::Geo(_)) | AscDesc::Desc(Member::Geo(_)) => { Err(CriterionError::ReservedNameForSort { name: "_geoPoint".to_string() })? } - Err(AscDescError::InvalidSyntax { name }) => { - Err(CriterionError::InvalidName { name })? - } - Err(AscDescError::ReservedKeyword { name }) if name.starts_with("_geoPoint") => { - Err(CriterionError::ReservedNameForSort { name: "_geoPoint".to_string() })? - } - Err(AscDescError::ReservedKeyword { name }) if name.starts_with("_geoRadius") => { - Err(CriterionError::ReservedNameForFilter { name: "_geoRadius".to_string() })? - } - Err(AscDescError::ReservedKeyword { name }) => { - Err(CriterionError::ReservedName { name })? - } }, } } } -impl From for Error { - fn from(error: CriterionError) -> Self { - Self::UserError(UserError::CriterionError(error)) - } -} - pub fn default_criteria() -> Vec { vec![ Criterion::Words,