/* 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 */ 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, ) -> Result { 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::, anyhow::Error>>()?; results.retain(|(n, _)| n.visibility >= Visibility::Reduced); let duration = timing.elapsed(); Ok(ApiSearchResponse { count, results, duration, }) }