- 服务层拆分:删除 api/helpers.rs,新增 citation/note/session/pipeline/paper/vision 独立服务模块
- Agent 工具精简:paper_content+paper_outline 合并为 paper.rs,图片分析逻辑下沉至 services/vision
- 并发模型升级:std::sync::{Mutex,RwLock} → tokio::sync::{Mutex,RwLock},消除 async
上下文中的阻塞风险
- 客户端加固:HTTP 客户端统一超时配置、ADS 429 / arXiv 503 自动重试、构造函数返回 Result
- 启动安全:全局 panic hook 日志化、空密码拒绝启动、向量表维度不匹配需显式确认
- CLI 扩展:构建完整 AppState 复用服务层,新增 Content/Outline/Citations/Search/Process 子命令
- 前端:移动端汉堡菜单、侧栏滑出面板、引用星系触屏手势(单指拖拽/双指缩放)
57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
// src/api/search.rs
|
||
//
|
||
// 跨会话全文搜索 API(P3 特性)。
|
||
// 使用 FTS5 BM25 排序搜索 agent_sessions 和 agent_messages。
|
||
|
||
use axum::{
|
||
extract::{Query, State},
|
||
Json,
|
||
};
|
||
use serde::Deserialize;
|
||
use std::sync::Arc;
|
||
|
||
use super::error::{ApiResult, AppError};
|
||
use super::AppState;
|
||
pub use crate::services::search::SearchResult;
|
||
|
||
#[derive(Debug, Deserialize)]
|
||
pub struct SearchParams {
|
||
/// 搜索关键词(支持 FTS5 查询语法)
|
||
pub q: String,
|
||
/// 搜索范围:sessions, messages, all(默认 all)
|
||
#[serde(default = "default_scope")]
|
||
pub scope: String,
|
||
/// 最大结果数(默认 20,最大 100)
|
||
#[serde(default = "default_limit")]
|
||
pub limit: i64,
|
||
/// 可选:限定到特定会话
|
||
pub session_id: Option<String>,
|
||
}
|
||
|
||
fn default_scope() -> String {
|
||
"all".into()
|
||
}
|
||
fn default_limit() -> i64 {
|
||
20
|
||
}
|
||
|
||
/// GET /api/search
|
||
pub async fn search(
|
||
State(state): State<Arc<AppState>>,
|
||
Query(params): Query<SearchParams>,
|
||
) -> ApiResult<Json<Vec<SearchResult>>> {
|
||
let limit = params.limit.min(100);
|
||
|
||
let results = crate::services::search::search_agent_history(
|
||
&state.db,
|
||
¶ms.q,
|
||
¶ms.scope,
|
||
limit,
|
||
params.session_id.as_deref(),
|
||
)
|
||
.await
|
||
.map_err(|e| AppError::internal(format!("全文检索失败: {}", e)))?;
|
||
|
||
Ok(Json(results))
|
||
}
|