Skip to main content

tdm_server_rust/entity/
search.rs

1//! 全局搜索 DTO。
2//!
3//! 统一承载漫画、话数、组员、术语、评价、问卷、奖励等分区搜索结果。
4
5use serde::{Deserialize, Serialize};
6
7/// 全局搜索请求参数。
8#[derive(Debug, Clone, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct GlobalSearchQuery {
11    /// 搜索关键词。
12    #[serde(default)]
13    pub q: String,
14    /// 搜索分区,缺省为 `all`。
15    #[serde(default, rename = "type")]
16    pub search_type: Option<String>,
17    /// 当前页码,从 1 开始。
18    #[serde(default = "default_page")]
19    pub page: i32,
20    /// 每页条数。
21    #[serde(default = "default_page_size")]
22    pub page_size: i32,
23}
24
25/// 全局搜索响应。
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28pub struct GlobalSearchResponse {
29    /// 原始搜索关键词。
30    pub query: String,
31    /// 当前搜索分区。
32    #[serde(rename = "type")]
33    pub search_type: String,
34    /// 当前页码。
35    pub page: i32,
36    /// 每页条数。
37    pub page_size: i32,
38    /// 当前可见权限范围内的总命中数。
39    pub total: i64,
40    /// 各分区命中数。
41    pub sections: Vec<GlobalSearchSectionCount>,
42    /// 当前页结果。
43    pub hits: Vec<GlobalSearchHit>,
44}
45
46/// 单个搜索分区命中统计。
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct GlobalSearchSectionCount {
50    /// 分区标识。
51    pub kind: String,
52    /// 分区展示名称。
53    pub label: String,
54    /// 分区命中总数。
55    pub total: i64,
56}
57
58/// 单条全局搜索结果。
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(rename_all = "camelCase")]
61pub struct GlobalSearchHit {
62    /// 结果唯一标识。
63    pub id: String,
64    /// 结果分区。
65    pub kind: String,
66    /// 分区展示名称。
67    pub kind_label: String,
68    /// 主标题。
69    pub title: String,
70    /// 副标题。
71    pub subtitle: Option<String>,
72    /// 命中的摘要内容。
73    pub highlight: Option<String>,
74    /// 前端跳转路径。
75    pub route: String,
76    /// 图片地址或 objectKey。
77    pub image_url: Option<String>,
78    /// 头像地址或 objectKey。
79    pub avatar_url: Option<String>,
80    /// 相关度得分。
81    pub score: f64,
82    /// 更新时间,ISO 字符串。
83    pub updated_at: Option<String>,
84}
85
86/// 默认页码。
87fn default_page() -> i32 {
88    1
89}
90
91/// 默认每页条数。
92fn default_page_size() -> i32 {
93    20
94}