mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-02-16 23:43:27 +01:00
Change the Asc/Desc criterion syntax to use a colon (:)
This commit is contained in:
parent
e9ada44509
commit
fcedff95e8
@ -25,7 +25,6 @@ obkv = "0.2.0"
|
|||||||
once_cell = "1.5.2"
|
once_cell = "1.5.2"
|
||||||
ordered-float = "2.1.1"
|
ordered-float = "2.1.1"
|
||||||
rayon = "1.5.0"
|
rayon = "1.5.0"
|
||||||
regex = "1.4.3"
|
|
||||||
roaring = "0.6.6"
|
roaring = "0.6.6"
|
||||||
serde = { version = "1.0.123", features = ["derive"] }
|
serde = { version = "1.0.123", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.62", features = ["preserve_order"] }
|
serde_json = { version = "1.0.62", features = ["preserve_order"] }
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use regex::Regex;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::{Error, UserError};
|
use crate::error::{Error, UserError};
|
||||||
|
|
||||||
static ASC_DESC_REGEX: Lazy<Regex> =
|
|
||||||
Lazy::new(|| Regex::new(r#"(asc|desc)\(([\w_-]+)\)"#).unwrap());
|
|
||||||
|
|
||||||
#[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.
|
||||||
@ -50,22 +45,11 @@ impl FromStr for Criterion {
|
|||||||
"proximity" => Ok(Criterion::Proximity),
|
"proximity" => Ok(Criterion::Proximity),
|
||||||
"attribute" => Ok(Criterion::Attribute),
|
"attribute" => Ok(Criterion::Attribute),
|
||||||
"exactness" => Ok(Criterion::Exactness),
|
"exactness" => Ok(Criterion::Exactness),
|
||||||
text => {
|
text => match text.rsplit_once(':') {
|
||||||
let caps = ASC_DESC_REGEX
|
Some((field_name, "asc")) => Ok(Criterion::Asc(field_name.to_string())),
|
||||||
.captures(text)
|
Some((field_name, "desc")) => Ok(Criterion::Desc(field_name.to_string())),
|
||||||
.ok_or_else(|| UserError::InvalidCriterionName { name: text.to_string() })?;
|
_ => Err(UserError::InvalidCriterionName { name: text.to_string() }.into()),
|
||||||
let order = caps.get(1).unwrap().as_str();
|
},
|
||||||
let field_name = caps.get(2).unwrap().as_str();
|
|
||||||
match order {
|
|
||||||
"asc" => Ok(Criterion::Asc(field_name.to_string())),
|
|
||||||
"desc" => Ok(Criterion::Desc(field_name.to_string())),
|
|
||||||
text => {
|
|
||||||
return Err(
|
|
||||||
UserError::InvalidCriterionName { name: text.to_string() }.into()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user