mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 18:45:06 +08:00
auto convert AscDescError into CriterionError
This commit is contained in:
parent
023446ecf3
commit
1e5e3d57e2
@ -4,7 +4,7 @@ use std::str::FromStr;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::{AscDesc, AscDescError, Member, UserError};
|
use crate::{AscDesc, Member, UserError};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CriterionError {
|
pub enum CriterionError {
|
||||||
@ -41,6 +41,12 @@ impl fmt::Display for CriterionError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<CriterionError> for Error {
|
||||||
|
fn from(error: CriterionError) -> Self {
|
||||||
|
Self::UserError(UserError::CriterionError(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||||
pub enum Criterion {
|
pub enum Criterion {
|
||||||
/// Sorted by decreasing number of matched query terms.
|
/// Sorted by decreasing number of matched query terms.
|
||||||
@ -85,35 +91,17 @@ impl FromStr for Criterion {
|
|||||||
"attribute" => Ok(Criterion::Attribute),
|
"attribute" => Ok(Criterion::Attribute),
|
||||||
"sort" => Ok(Criterion::Sort),
|
"sort" => Ok(Criterion::Sort),
|
||||||
"exactness" => Ok(Criterion::Exactness),
|
"exactness" => Ok(Criterion::Exactness),
|
||||||
text => match AscDesc::from_str(text) {
|
text => match AscDesc::from_str(text)? {
|
||||||
Ok(AscDesc::Asc(Member::Field(field))) => Ok(Criterion::Asc(field)),
|
AscDesc::Asc(Member::Field(field)) => Ok(Criterion::Asc(field)),
|
||||||
Ok(AscDesc::Desc(Member::Field(field))) => Ok(Criterion::Desc(field)),
|
AscDesc::Desc(Member::Field(field)) => Ok(Criterion::Desc(field)),
|
||||||
Ok(AscDesc::Asc(Member::Geo(_))) | Ok(AscDesc::Desc(Member::Geo(_))) => {
|
AscDesc::Asc(Member::Geo(_)) | AscDesc::Desc(Member::Geo(_)) => {
|
||||||
Err(CriterionError::ReservedNameForSort { name: "_geoPoint".to_string() })?
|
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<CriterionError> for Error {
|
|
||||||
fn from(error: CriterionError) -> Self {
|
|
||||||
Self::UserError(UserError::CriterionError(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn default_criteria() -> Vec<Criterion> {
|
pub fn default_criteria() -> Vec<Criterion> {
|
||||||
vec![
|
vec![
|
||||||
Criterion::Words,
|
Criterion::Words,
|
||||||
|
Loading…
Reference in New Issue
Block a user