zhibo/模块文档/08-搜索功能模块.md

298 lines
4.4 KiB
Markdown
Raw Normal View History

2025-12-30 11:11:11 +08:00
# 搜索功能模块接口文档
## 模块概述
搜索功能模块提供用户、直播间、作品的搜索,以及热门搜索、搜索历史等功能。
---
## 接口列表
### 1. 搜索用户
**接口路径**: `GET /api/front/search/users`
**请求参数**:
```
keyword: 搜索关键词
pageNum: 页码 (默认1)
pageSize: 每页数量 (默认20)
```
**返回参数**:
```json
{
"code": 200,
"msg": "success",
"data": {
"list": [
{
"userId": 用户ID,
"nickname": "昵称",
"avatar": "头像URL",
"phone": "手机号",
"isFollowing": false
}
],
"total": 总数,
"pageNum": 当前页,
"pageSize": 每页数量
}
}
```
---
### 2. 搜索直播间
**接口路径**: `GET /api/front/search/live-rooms`
**请求参数**:
```
keyword: 搜索关键词
categoryId: 分类ID (可选)
isLive: 是否直播中 (可选)
pageNum: 页码 (默认1)
pageSize: 每页数量 (默认20)
```
**返回参数**:
```json
{
"code": 200,
"msg": "success",
"data": {
"list": [
{
"id": "房间ID",
"title": "直播间标题",
"streamerName": "主播名称",
"coverImage": "封面图",
"isLive": true,
"viewerCount": 1234,
"categoryName": "分类名称"
}
],
"total": 总数,
"pageNum": 当前页,
"pageSize": 每页数量
}
}
```
---
### 3. 搜索作品
**接口路径**: `GET /api/front/search/works`
**请求参数**:
```
keyword: 搜索关键词
categoryId: 分类ID (可选)
pageNum: 页码 (默认1)
pageSize: 每页数量 (默认20)
```
**返回参数**:
```json
{
"code": 200,
"msg": "success",
"data": {
"list": [
{
"id": 作品ID,
"title": "作品标题",
"coverUrl": "封面URL",
"type": "IMAGE",
"authorName": "作者昵称",
"likeCount": 点赞数,
"isLiked": false,
"isCollected": false
}
],
"total": 总数,
"pageNum": 当前页,
"pageSize": 每页数量
}
}
```
---
### 4. 综合搜索
**接口路径**: `GET /api/front/search/all`
**请求参数**:
```
keyword: 搜索关键词
```
**返回参数**:
```json
{
"code": 200,
"msg": "success",
"data": {
"users": [
{
"userId": 用户ID,
"nickname": "昵称",
"avatar": "头像URL"
}
],
"liveRooms": [
{
"id": "房间ID",
"title": "直播间标题",
"streamerName": "主播名称"
}
],
"works": [
{
"id": 作品ID,
"title": "作品标题",
"coverUrl": "封面URL"
}
]
}
}
```
**说明**: 返回各类型的前几条结果
---
### 5. 获取热门搜索
**接口路径**: `GET /api/front/search/hot`
**请求参数**:
```
searchType: 搜索类型 (0-全部 1-用户 2-直播间 3-作品)
limit: 返回数量 (默认10)
```
**返回参数**:
```json
{
"code": 200,
"msg": "success",
"data": [
{
"keyword": "关键词",
"searchCount": 搜索次数
}
]
}
```
---
### 6. 获取搜索历史
**接口路径**: `GET /api/front/search/history`
**请求头**:
```
Authorization: Bearer {token}
```
**请求参数**:
```
searchType: 搜索类型 (可选)
limit: 返回数量 (默认20)
```
**返回参数**:
```json
{
"code": 200,
"msg": "success",
"data": [
{
"id": 历史ID,
"keyword": "关键词",
"searchType": 搜索类型,
"createTime": "创建时间"
}
]
}
```
---
### 7. 清除搜索历史
**接口路径**: `DELETE /api/front/search/history`
**请求头**:
```
Authorization: Bearer {token}
```
**请求参数**:
```
searchType: 搜索类型 (可选,不传则清除全部)
```
**返回参数**:
```json
{
"code": 200,
"msg": "搜索历史已清除"
}
```
---
### 8. 删除单条搜索历史
**接口路径**: `DELETE /api/front/search/history/{historyId}`
**请求头**:
```
Authorization: Bearer {token}
```
**请求参数**:
```
historyId: 历史ID (路径参数)
```
**返回参数**:
```json
{
"code": 200,
"msg": "删除成功"
}
```
---
### 9. 获取搜索建议
**接口路径**: `GET /api/front/search/suggestions`
**请求头**:
```
Authorization: Bearer {token}
```
**请求参数**:
```
keyword: 关键词前缀
searchType: 搜索类型 (可选)
limit: 返回数量 (默认10)
```
**返回参数**:
```json
{
"code": 200,
"msg": "success",
"data": ["建议1", "建议2", "建议3"]
}
```