Apply additional categories fix to search indexing (#428)

* Apply additional categories fix to search indexing

* fix edit version validator
This commit is contained in:
Geometrically
2022-08-20 22:34:00 -07:00
committed by GitHub
parent 76c0fa2fe2
commit 9c7b34d5e6
3 changed files with 178 additions and 169 deletions

View File

@@ -167,7 +167,7 @@ pub async fn version_get(
#[derive(Serialize, Deserialize, Validate)]
pub struct EditVersion {
#[validate(length(min = 3, max = 256))]
#[validate(length(min = 1, max = 256))]
pub name: Option<String>,
#[validate(
length(min = 1, max = 64),

View File

@@ -17,12 +17,13 @@ pub async fn index_local(
m.icon_url icon_url, m.published published, m.approved approved, m.updated updated,
m.team_id team_id, m.license license, m.slug slug,
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, pt.name project_type_name, u.username username,
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null) categories, ARRAY_AGG(DISTINCT ca.category) filter (where ca.category is not null) additional_categories, ARRAY_AGG(DISTINCT lo.loader) filter (where lo.loader is not null) loaders, ARRAY_AGG(DISTINCT gv.version) filter (where gv.version is not null) versions,
ARRAY_AGG(DISTINCT c.category || ' |||| ' || mc.is_additional) filter (where c.category is not null) categories,
ARRAY_AGG(DISTINCT lo.loader) filter (where lo.loader is not null) loaders,
ARRAY_AGG(DISTINCT gv.version) filter (where gv.version is not null) versions,
ARRAY_AGG(DISTINCT mg.image_url) filter (where mg.image_url is not null) gallery
FROM mods m
LEFT OUTER JOIN mods_categories mc ON joining_mod_id = m.id
LEFT OUTER JOIN categories c ON mc.joining_category_id = c.id AND mc.is_additional = FALSE
LEFT OUTER JOIN categories ca ON mc.joining_category_id = ca.id AND mc.is_additional = TRUE
LEFT OUTER JOIN categories c ON mc.joining_category_id = c.id
LEFT OUTER JOIN versions v ON v.mod_id = m.id
LEFT OUTER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id
LEFT OUTER JOIN game_versions gv ON gvv.game_version_id = gv.id
@@ -46,13 +47,27 @@ pub async fn index_local(
.fetch_many(&pool)
.try_filter_map(|e| async {
Ok(e.right().map(|m| {
let mut categories = m.categories.unwrap_or_default();
let categories_raw = m.categories.unwrap_or_default();
let mut additional_categories = Vec::new();
let mut categories = Vec::new();
for category in categories_raw {
let category: Vec<&str> = category.split(" |||| ").collect();
if category.len() >= 2 {
if category[1].parse::<bool>().ok().unwrap_or_default() {
additional_categories.push(category[0].to_string());
} else {
categories.push(category[0].to_string());
}
}
}
categories.append(&mut m.loaders.unwrap_or_default());
let primary_categories = categories.clone();
categories.append(&mut m.additional_categories.unwrap_or_default());
let display_categories = categories.clone();
categories.append(&mut additional_categories.clone());
let versions = m.versions.unwrap_or_default();
@@ -79,7 +94,7 @@ pub async fn index_local(
slug: m.slug,
project_type: m.project_type_name,
gallery: m.gallery.unwrap_or_default(),
display_categories: primary_categories
display_categories
}
}))
})