diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-02 23:16:59 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-02 23:16:59 +0100 |
commit | e3daa6159f2b2048c2c07d349488e117e50285dd (patch) | |
tree | 4d2d2fc24fba0a3516b852a806cc7e14dd0f2b58 /server/src/routes/ui | |
parent | c4d40a34be067872e8b6f59520ab9da8d89b70e0 (diff) | |
download | jellything-e3daa6159f2b2048c2c07d349488e117e50285dd.tar jellything-e3daa6159f2b2048c2c07d349488e117e50285dd.tar.bz2 jellything-e3daa6159f2b2048c2c07d349488e117e50285dd.tar.zst |
restore search functionality
Diffstat (limited to 'server/src/routes/ui')
-rw-r--r-- | server/src/routes/ui/admin/mod.rs | 24 | ||||
-rw-r--r-- | server/src/routes/ui/search.rs | 4 |
2 files changed, 26 insertions, 2 deletions
diff --git a/server/src/routes/ui/admin/mod.rs b/server/src/routes/ui/admin/mod.rs index 50faa2e..62a06bc 100644 --- a/server/src/routes/ui/admin/mod.rs +++ b/server/src/routes/ui/admin/mod.rs @@ -26,7 +26,7 @@ use markup::DynRender; use rand::Rng; use rocket::{form::Form, get, post, FromForm, State}; use std::time::Instant; -use tokio::sync::Semaphore; +use tokio::{sync::Semaphore, task::spawn_blocking}; use user::rocket_uri_macro_r_admin_users; #[get("/admin/dashboard")] @@ -85,6 +85,9 @@ pub async fn admin_dashboard<'a>( form[method="POST", action=uri!(r_admin_transcode_posters())] { input[type="submit", disabled=is_transcoding(), value="Transcode all posters with low resolution"]; } + form[method="POST", action=uri!(r_admin_update_search())] { + input[type="submit", value="Update full-text search index"]; + } form[method="POST", action=uri!(r_admin_delete_cache())] { input.danger[type="submit", value="Delete Cache"]; } @@ -163,6 +166,25 @@ pub async fn r_admin_import( admin_dashboard(database, Some(flash)).await } +#[post("/admin/update_search")] +pub async fn r_admin_update_search( + _session: AdminSession, + database: &State<Database>, +) -> MyResult<DynLayoutPage<'static>> { + let db2 = (*database).clone(); + let r = spawn_blocking(move || db2.search_create_index()) + .await + .unwrap(); + admin_dashboard( + &database, + Some( + r.map_err(|e| e.into()) + .map(|_| format!("Search index updated")), + ), + ) + .await +} + #[post("/admin/delete_cache")] pub async fn r_admin_delete_cache( session: AdminSession, diff --git a/server/src/routes/ui/search.rs b/server/src/routes/ui/search.rs index ac37b80..6b1504f 100644 --- a/server/src/routes/ui/search.rs +++ b/server/src/routes/ui/search.rs @@ -5,6 +5,7 @@ use super::{ node::{DatabaseNodeUserDataExt, NodeCard}, }; use jellybase::database::Database; +use jellycommon::Visibility; use rocket::{get, State}; use std::time::Instant; @@ -18,10 +19,11 @@ pub async fn r_search<'a>( let timing = Instant::now(); let results = if let Some(query) = query { let (count, ids) = db.search(query, page.unwrap_or_default())?; - let nodes = ids + let mut nodes = ids .into_iter() .map(|id| db.get_node_with_userdata(id, &session)) .collect::<Result<Vec<_>, anyhow::Error>>()?; + nodes.retain(|(n, _)| n.visibility >= Visibility::Reduced); Some((count, nodes)) } else { None |