change wording of custom ranking rules dsc -> desc; #490

This commit is contained in:
qdequele 2020-03-02 17:13:23 +01:00 committed by Quentin de Quelen
parent 4d27318b72
commit 6016f2e941
7 changed files with 34 additions and 34 deletions

View File

@ -1065,7 +1065,7 @@ mod tests {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)" "desc(release_date)"
], ],
"searchableAttributes": ["name", "release_date"], "searchableAttributes": ["name", "release_date"],
"displayedAttributes": ["name", "release_date"] "displayedAttributes": ["name", "release_date"]

View File

@ -10,7 +10,7 @@ use self::RankingRule::*;
pub const DEFAULT_RANKING_RULES: [RankingRule; 6] = [Typo, Words, Proximity, Attribute, WordsPosition, Exactness]; pub const DEFAULT_RANKING_RULES: [RankingRule; 6] = [Typo, Words, Proximity, Attribute, WordsPosition, Exactness];
static RANKING_RULE_REGEX: Lazy<regex::Regex> = Lazy::new(|| { static RANKING_RULE_REGEX: Lazy<regex::Regex> = Lazy::new(|| {
let regex = regex::Regex::new(r"(asc|dsc)\(([a-zA-Z0-9-_]*)\)").unwrap(); let regex = regex::Regex::new(r"(asc|desc)\(([a-zA-Z0-9-_]*)\)").unwrap();
regex regex
}); });
@ -99,7 +99,7 @@ pub enum RankingRule {
WordsPosition, WordsPosition,
Exactness, Exactness,
Asc(String), Asc(String),
Dsc(String), Desc(String),
} }
impl std::fmt::Display for RankingRule { impl std::fmt::Display for RankingRule {
@ -112,7 +112,7 @@ impl std::fmt::Display for RankingRule {
RankingRule::WordsPosition => f.write_str("wordsPosition"), RankingRule::WordsPosition => f.write_str("wordsPosition"),
RankingRule::Exactness => f.write_str("exactness"), RankingRule::Exactness => f.write_str("exactness"),
RankingRule::Asc(field) => write!(f, "asc({})", field), RankingRule::Asc(field) => write!(f, "asc({})", field),
RankingRule::Dsc(field) => write!(f, "dsc({})", field), RankingRule::Desc(field) => write!(f, "desc({})", field),
} }
} }
} }
@ -132,7 +132,7 @@ impl FromStr for RankingRule {
let captures = RANKING_RULE_REGEX.captures(s).ok_or(RankingRuleConversionError)?; let captures = RANKING_RULE_REGEX.captures(s).ok_or(RankingRuleConversionError)?;
match (captures.get(1).map(|m| m.as_str()), captures.get(2)) { match (captures.get(1).map(|m| m.as_str()), captures.get(2)) {
(Some("asc"), Some(field)) => RankingRule::Asc(field.as_str().to_string()), (Some("asc"), Some(field)) => RankingRule::Asc(field.as_str().to_string()),
(Some("dsc"), Some(field)) => RankingRule::Dsc(field.as_str().to_string()), (Some("desc"), Some(field)) => RankingRule::Desc(field.as_str().to_string()),
_ => return Err(RankingRuleConversionError) _ => return Err(RankingRuleConversionError)
} }
} }
@ -144,7 +144,7 @@ impl FromStr for RankingRule {
impl RankingRule { impl RankingRule {
pub fn field(&self) -> Option<&str> { pub fn field(&self) -> Option<&str> {
match self { match self {
RankingRule::Asc(field) | RankingRule::Dsc(field) => Some(field), RankingRule::Asc(field) | RankingRule::Desc(field) => Some(field),
_ => None, _ => None,
} }
} }

View File

@ -313,7 +313,7 @@ impl<'a> SearchBuilder<'a> {
Err(err) => error!("Error during criteria builder; {:?}", err), Err(err) => error!("Error during criteria builder; {:?}", err),
} }
} }
RankingRule::Dsc(field) => { RankingRule::Desc(field) => {
match SortByAttr::higher_is_better(&ranked_map, &schema, &field) { match SortByAttr::higher_is_better(&ranked_map, &schema, &field) {
Ok(rule) => builder.push(rule), Ok(rule) => builder.push(rule),
Err(err) => error!("Error during criteria builder; {:?}", err), Err(err) => error!("Error during criteria builder; {:?}", err),

View File

@ -62,9 +62,9 @@ pub fn enrich_server_with_movies_settings(
"proximity", "proximity",
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"dsc(popularity)", "desc(popularity)",
"exactness", "exactness",
"dsc(vote_average)", "desc(vote_average)",
], ],
"distinctAttribute": null, "distinctAttribute": null,
"searchableAttributes": [ "searchableAttributes": [

View File

@ -631,9 +631,9 @@ fn search_with_settings_basic() {
"proximity", "proximity",
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"dsc(popularity)", "desc(popularity)",
"exactness", "exactness",
"dsc(vote_average)" "desc(vote_average)"
], ],
"distinctAttribute": null, "distinctAttribute": null,
"identifier": "id", "identifier": "id",
@ -737,9 +737,9 @@ fn search_with_settings_stop_words() {
"proximity", "proximity",
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"dsc(popularity)", "desc(popularity)",
"exactness", "exactness",
"dsc(vote_average)" "desc(vote_average)"
], ],
"distinctAttribute": null, "distinctAttribute": null,
"identifier": "id", "identifier": "id",
@ -844,9 +844,9 @@ fn search_with_settings_synonyms() {
"proximity", "proximity",
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"dsc(popularity)", "desc(popularity)",
"exactness", "exactness",
"dsc(vote_average)" "desc(vote_average)"
], ],
"distinctAttribute": null, "distinctAttribute": null,
"identifier": "id", "identifier": "id",
@ -958,7 +958,7 @@ fn search_with_settings_ranking_rules() {
"wordsPosition", "wordsPosition",
"asc(vote_average)", "asc(vote_average)",
"exactness", "exactness",
"dsc(popularity)" "desc(popularity)"
], ],
"distinctAttribute": null, "distinctAttribute": null,
"identifier": "id", "identifier": "id",
@ -1063,9 +1063,9 @@ fn search_with_settings_searchable_attributes() {
"proximity", "proximity",
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"dsc(popularity)", "desc(popularity)",
"exactness", "exactness",
"dsc(vote_average)" "desc(vote_average)"
], ],
"distinctAttribute": null, "distinctAttribute": null,
"identifier": "id", "identifier": "id",
@ -1169,9 +1169,9 @@ fn search_with_settings_displayed_attributes() {
"proximity", "proximity",
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"dsc(popularity)", "desc(popularity)",
"exactness", "exactness",
"dsc(vote_average)" "desc(vote_average)"
], ],
"distinctAttribute": null, "distinctAttribute": null,
"identifier": "id", "identifier": "id",
@ -1240,9 +1240,9 @@ fn search_with_settings_searchable_attributes_2() {
"proximity", "proximity",
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"dsc(popularity)", "desc(popularity)",
"exactness", "exactness",
"dsc(vote_average)" "desc(vote_average)"
], ],
"distinctAttribute": null, "distinctAttribute": null,
"identifier": "id", "identifier": "id",

View File

@ -47,8 +47,8 @@ fn write_all_and_delete() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
"dsc(rank)", "desc(rank)",
], ],
"distinctAttribute": "movie_id", "distinctAttribute": "movie_id",
"searchableAttributes": [ "searchableAttributes": [
@ -198,8 +198,8 @@ fn write_all_and_update() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
"dsc(rank)", "desc(rank)",
], ],
"distinctAttribute": "movie_id", "distinctAttribute": "movie_id",
"searchableAttributes": [ "searchableAttributes": [
@ -264,7 +264,7 @@ fn write_all_and_update() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
], ],
"searchableAttributes": [ "searchableAttributes": [
"title", "title",
@ -317,7 +317,7 @@ fn write_all_and_update() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
], ],
"distinctAttribute": null, "distinctAttribute": null,
"searchableAttributes": [ "searchableAttributes": [

View File

@ -45,8 +45,8 @@ fn write_all_and_delete() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
"dsc(rank)", "desc(rank)",
]); ]);
let body = json.to_string().into_bytes(); let body = json.to_string().into_bytes();
@ -143,8 +143,8 @@ fn write_all_and_update() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
"dsc(rank)", "desc(rank)",
]); ]);
let body = json.to_string().into_bytes(); let body = json.to_string().into_bytes();
@ -180,7 +180,7 @@ fn write_all_and_update() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
]); ]);
let body_update = json_update.to_string().into_bytes(); let body_update = json_update.to_string().into_bytes();
@ -212,7 +212,7 @@ fn write_all_and_update() {
"attribute", "attribute",
"wordsPosition", "wordsPosition",
"exactness", "exactness",
"dsc(release_date)", "desc(release_date)",
]); ]);
assert_json_eq!(res_expected, res_value, ordered: false); assert_json_eq!(res_expected, res_value, ordered: false);