You've already forked AstralRinth
forked from didirus/AstralRinth
Fix melisearch name replacements with operators other than : (#845)
* Fix melisearch name replacements with operators other than : * Pass facet by refrence --------- Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -78,7 +78,7 @@ pub async fn project_search(
|
|||||||
})
|
})
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
||||||
// These loaders speciically used to be combined with 'mod' to be a plugin, but now
|
// These loaders specifically used to be combined with 'mod' to be a plugin, but now
|
||||||
// they are their own loader type. We will convert 'mod' to 'mod' OR 'plugin'
|
// they are their own loader type. We will convert 'mod' to 'mod' OR 'plugin'
|
||||||
// as it essentially was before.
|
// as it essentially was before.
|
||||||
let facets = v2_reroute::convert_plugin_loaders_v3(facets);
|
let facets = v2_reroute::convert_plugin_loaders_v3(facets);
|
||||||
@@ -93,17 +93,13 @@ pub async fn project_search(
|
|||||||
facets
|
facets
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|facet| {
|
.map(|facet| {
|
||||||
let val = match facet.split(':').nth(1) {
|
if let Some((key, operator, val)) = parse_facet(&facet) {
|
||||||
Some(val) => val,
|
format!("{}{}{}", match key.as_str() {
|
||||||
None => return facet.to_string(),
|
"versions" => "game_versions",
|
||||||
};
|
"project_type" => "project_types",
|
||||||
|
"title" => "name",
|
||||||
if facet.starts_with("versions:") {
|
x => x,
|
||||||
format!("game_versions:{}", val)
|
}, operator, val)
|
||||||
} else if facet.starts_with("project_type:") {
|
|
||||||
format!("project_types:{}", val)
|
|
||||||
} else if facet.starts_with("title:") {
|
|
||||||
format!("name:{}", val)
|
|
||||||
} else {
|
} else {
|
||||||
facet.to_string()
|
facet.to_string()
|
||||||
}
|
}
|
||||||
@@ -130,6 +126,39 @@ pub async fn project_search(
|
|||||||
Ok(HttpResponse::Ok().json(results))
|
Ok(HttpResponse::Ok().json(results))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parses a facet into a key, operator, and value
|
||||||
|
fn parse_facet(facet: &String) -> Option<(String, String, String)> {
|
||||||
|
let mut key = String::new();
|
||||||
|
let mut operator = String::new();
|
||||||
|
let mut val = String::new();
|
||||||
|
|
||||||
|
let mut iterator = facet.chars();
|
||||||
|
while let Some(char) = iterator.next() {
|
||||||
|
match char {
|
||||||
|
':' | '=' => {
|
||||||
|
operator.push(char);
|
||||||
|
val = iterator.collect::<String>();
|
||||||
|
return Some((key, operator, val));
|
||||||
|
}
|
||||||
|
'<' | '>' => {
|
||||||
|
operator.push(char);
|
||||||
|
if let Some(next_char) = iterator.next() {
|
||||||
|
if next_char == '=' {
|
||||||
|
operator.push(next_char);
|
||||||
|
} else {
|
||||||
|
val.push(next_char);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val.push_str(&iterator.collect::<String>());
|
||||||
|
return Some((key, operator, val));
|
||||||
|
}
|
||||||
|
_ => key.push(char),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Validate)]
|
#[derive(Deserialize, Validate)]
|
||||||
pub struct RandomProjects {
|
pub struct RandomProjects {
|
||||||
#[validate(range(min = 1, max = 100))]
|
#[validate(range(min = 1, max = 100))]
|
||||||
|
|||||||
Reference in New Issue
Block a user