You've already forked AstralRinth
forked from didirus/AstralRinth
Add dependencies to search (#578)
* Add dependencies to search * add attrs for faceting * run prepare * Add user data route from token * update to 24hrs * Fix report bugs
This commit is contained in:
@@ -4,11 +4,10 @@ use log::info;
|
||||
use super::IndexingError;
|
||||
use crate::database::models::ProjectId;
|
||||
use crate::search::UploadSearchProject;
|
||||
use serde::Deserialize;
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
pub async fn index_local(
|
||||
pool: PgPool,
|
||||
) -> Result<Vec<UploadSearchProject>, IndexingError> {
|
||||
pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchProject>, IndexingError> {
|
||||
info!("Indexing local projects!");
|
||||
|
||||
Ok(
|
||||
@@ -23,7 +22,8 @@ pub async fn index_local(
|
||||
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 and mg.featured is false) gallery,
|
||||
ARRAY_AGG(DISTINCT mg.image_url) filter (where mg.image_url is not null and mg.featured is true) featured_gallery
|
||||
ARRAY_AGG(DISTINCT mg.image_url) filter (where mg.image_url is not null and mg.featured is true) featured_gallery,
|
||||
JSONB_AGG(DISTINCT jsonb_build_object('id', mdep.id, 'dep_type', d.dependency_type)) filter (where mdep.id is not null) dependencies
|
||||
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
|
||||
@@ -33,6 +33,8 @@ pub async fn index_local(
|
||||
LEFT OUTER JOIN loaders_versions lv ON lv.version_id = v.id
|
||||
LEFT OUTER JOIN loaders lo ON lo.id = lv.loader_id
|
||||
LEFT OUTER JOIN mods_gallery mg ON mg.mod_id = m.id
|
||||
LEFT OUTER JOIN dependencies d ON d.dependent_id = v.id
|
||||
LEFT OUTER JOIN mods mdep ON mdep.id = d.mod_dependency_id
|
||||
INNER JOIN project_types pt ON pt.id = m.project_type
|
||||
INNER JOIN side_types cs ON m.client_side = cs.id
|
||||
INNER JOIN side_types ss ON m.server_side = ss.id
|
||||
@@ -70,6 +72,21 @@ pub async fn index_local(
|
||||
_ => false,
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct TempDependency {
|
||||
id: ProjectId,
|
||||
dep_type: String
|
||||
}
|
||||
|
||||
let dependencies = serde_json::from_value::<Vec<TempDependency>>(
|
||||
m.dependencies.unwrap_or_default(),
|
||||
)
|
||||
.ok()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|x| format!("{}-{}", crate::models::ids::ProjectId::from(x.id), x.dep_type))
|
||||
.collect();
|
||||
|
||||
UploadSearchProject {
|
||||
project_id: project_id.to_string(),
|
||||
title: m.title,
|
||||
@@ -95,6 +112,7 @@ pub async fn index_local(
|
||||
open_source,
|
||||
color: m.color.map(|x| x as u32),
|
||||
featured_gallery: m.featured_gallery.unwrap_or_default().first().cloned(),
|
||||
dependencies,
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
@@ -203,10 +203,10 @@ const DEFAULT_DISPLAYED_ATTRIBUTES: &[&str] = &[
|
||||
"gallery",
|
||||
"featured_gallery",
|
||||
"color",
|
||||
"dependencies",
|
||||
];
|
||||
|
||||
const DEFAULT_SEARCHABLE_ATTRIBUTES: &[&str] =
|
||||
&["title", "description", "author", "slug"];
|
||||
const DEFAULT_SEARCHABLE_ATTRIBUTES: &[&str] = &["title", "description", "author", "slug"];
|
||||
|
||||
const DEFAULT_ATTRIBUTES_FOR_FACETING: &[&str] = &[
|
||||
"categories",
|
||||
@@ -224,6 +224,7 @@ const DEFAULT_ATTRIBUTES_FOR_FACETING: &[&str] = &[
|
||||
"project_id",
|
||||
"open_source",
|
||||
"color",
|
||||
"dependencies",
|
||||
];
|
||||
|
||||
const DEFAULT_SORTABLE_ATTRIBUTES: &[&str] =
|
||||
|
||||
@@ -99,6 +99,8 @@ pub struct UploadSearchProject {
|
||||
pub modified_timestamp: i64,
|
||||
pub open_source: bool,
|
||||
pub color: Option<u32>,
|
||||
/// format: {project_id}-{dep_type}
|
||||
pub dependencies: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@@ -134,6 +136,8 @@ pub struct ResultSearchProject {
|
||||
pub gallery: Vec<String>,
|
||||
pub featured_gallery: Option<String>,
|
||||
pub color: Option<u32>,
|
||||
/// format: {project_id}-{dep_type}
|
||||
pub dependencies: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn search_for_project(
|
||||
@@ -177,13 +181,12 @@ pub async fn search_for_project(
|
||||
None
|
||||
};
|
||||
|
||||
let filters: Cow<_> =
|
||||
match (info.filters.as_deref(), info.version.as_deref()) {
|
||||
(Some(f), Some(v)) => format!("({f}) AND ({v})").into(),
|
||||
(Some(f), None) => f.into(),
|
||||
(None, Some(v)) => v.into(),
|
||||
(None, None) => "".into(),
|
||||
};
|
||||
let filters: Cow<_> = match (info.filters.as_deref(), info.version.as_deref()) {
|
||||
(Some(f), Some(v)) => format!("({f}) AND ({v})").into(),
|
||||
(Some(f), None) => f.into(),
|
||||
(None, Some(v)) => v.into(),
|
||||
(None, None) => "".into(),
|
||||
};
|
||||
|
||||
if let Some(facets) = facets {
|
||||
filter_string.push('(');
|
||||
|
||||
Reference in New Issue
Block a user