Merge pull request #141 from meilisearch/reorganize-criterion

reorganize criterion
This commit is contained in:
Clément Renault 2021-04-01 19:50:16 +02:00 committed by GitHub
commit 2bcdd8844c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,18 +14,16 @@ static ASC_DESC_REGEX: Lazy<Regex> = Lazy::new(|| {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Criterion {
/// Sorted by decreasing number of matched query terms.
/// Query words at the front of an attribute is considered better than if it was at the back.
Words,
/// Sorted by increasing number of typos.
Typo,
/// Sorted by decreasing number of matched query terms.
Words,
/// Sorted by increasing distance between matched query terms.
Proximity,
/// Documents with quey words contained in more important
/// attributes are considred better.
Attribute,
/// Documents with query words at the front of an attribute is
/// considered better than if it was at the back.
WordsPosition,
/// Sorted by the similarity of the matched words with the query words.
Exactness,
/// Sorted by the increasing value of the field specified.
@ -37,11 +35,10 @@ pub enum Criterion {
impl Criterion {
pub fn from_str(faceted_attributes: &HashMap<String, FacetType>, txt: &str) -> anyhow::Result<Criterion> {
match txt {
"typo" => Ok(Criterion::Typo),
"words" => Ok(Criterion::Words),
"typo" => Ok(Criterion::Typo),
"proximity" => Ok(Criterion::Proximity),
"attribute" => Ok(Criterion::Attribute),
"wordsposition" => Ok(Criterion::WordsPosition),
"exactness" => Ok(Criterion::Exactness),
text => {
let caps = ASC_DESC_REGEX.captures(text).with_context(|| format!("unknown criterion name: {}", text))?;
@ -60,11 +57,10 @@ impl Criterion {
pub fn default_criteria() -> Vec<Criterion> {
vec![
Criterion::Typo,
Criterion::Words,
Criterion::Typo,
Criterion::Proximity,
Criterion::Attribute,
Criterion::WordsPosition,
Criterion::Exactness,
]
}
@ -74,11 +70,10 @@ impl fmt::Display for Criterion {
use Criterion::*;
match self {
Typo => f.write_str("typo"),
Words => f.write_str("words"),
Typo => f.write_str("typo"),
Proximity => f.write_str("proximity"),
Attribute => f.write_str("attribute"),
WordsPosition => f.write_str("wordsPosition"),
Exactness => f.write_str("exactness"),
Asc(attr) => write!(f, "asc({})", attr),
Desc(attr) => write!(f, "desc({})", attr),