aboutsummaryrefslogtreecommitdiff
path: root/logic/src/search.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-04-28 18:27:03 +0200
committermetamuffin <metamuffin@disroot.org>2025-04-28 18:27:03 +0200
commit51761cbdefa39107b9e1f931f1aa8df6aebb2a94 (patch)
tree957ca180786ece777e6e1153ada91da741d845ec /logic/src/search.rs
parent80d28b764c95891551e28c395783f5ff9d065743 (diff)
downloadjellything-51761cbdefa39107b9e1f931f1aa8df6aebb2a94.tar
jellything-51761cbdefa39107b9e1f931f1aa8df6aebb2a94.tar.bz2
jellything-51761cbdefa39107b9e1f931f1aa8df6aebb2a94.tar.zst
many much more generic refactor
Diffstat (limited to 'logic/src/search.rs')
-rw-r--r--logic/src/search.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/logic/src/search.rs b/logic/src/search.rs
new file mode 100644
index 0000000..8e41e27
--- /dev/null
+++ b/logic/src/search.rs
@@ -0,0 +1,31 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2025 metamuffin <metamuffin.org>
+*/
+use crate::{node::DatabaseNodeUserDataExt, session::Session};
+use anyhow::Result;
+use jellybase::database::Database;
+use jellycommon::{Visibility, api::ApiSearchResponse};
+use std::time::Instant;
+
+pub fn search(
+ db: &Database,
+ session: &Session,
+ query: &str,
+ page: Option<usize>,
+) -> Result<ApiSearchResponse> {
+ let timing = Instant::now();
+ let (count, ids) = db.search(query, 32, page.unwrap_or_default() * 32)?;
+ let mut results = ids
+ .into_iter()
+ .map(|id| db.get_node_with_userdata(id, &session))
+ .collect::<Result<Vec<_>, anyhow::Error>>()?;
+ results.retain(|(n, _)| n.visibility >= Visibility::Reduced);
+ let duration = timing.elapsed();
+ Ok(ApiSearchResponse {
+ count,
+ results,
+ duration,
+ })
+}