update the default ordering of the criterion

This commit is contained in:
tamo 2021-04-01 19:13:18 +02:00
parent ee3f93c029
commit 0a4bde1f2f
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69

View File

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