1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/*
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::{DATABASE, node::DatabaseNodeUserDataExt, session::Session};
use anyhow::Result;
use jellycommon::{Visibility, api::ApiSearchResponse};
use std::time::Instant;
pub fn search(session: &Session, query: &str, page: Option<usize>) -> Result<ApiSearchResponse> {
let timing = Instant::now();
let (count, ids) = DATABASE.search(query, 32, page.unwrap_or_default() * 32)?;
let mut results = ids
.into_iter()
.map(|id| DATABASE.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,
})
}
|