RPC 函数详情
搜索相关
search_comics_pgroonga 全文搜索与 get_random_comics 随机推荐
search_comics_pgroonga
PGroonga 全文搜索函数,支持按关键词搜索漫画(匹配标题、拼音、别名),同时支持分类筛选、连载状态筛选、多种排序方式和分页。当搜索词为空时退化为带筛选的浏览模式。
| 属性 | 值 |
|---|---|
| 安全级别 | SECURITY DEFINER |
| 搜索引擎 | PGroonga(&@~ 全文匹配运算符) |
| 匹配范围 | title + pinyin_name + aliases(JSONB 数组转文本) |
参数
Prop
Type
sort_by 可选值
| 值 | 排序依据 |
|---|---|
created_at | 创建时间(默认) |
updated_at | 更新时间 |
popularity_daily | 日人气 |
popularity_weekly | 周人气 |
popularity_monthly | 月人气 |
rating_average | 平均评分 |
view_count | 总浏览量 |
title | 标题字母序 |
返回字段
每行包含完整的漫画信息以及额外的聚合字段:
| 字段 | 类型 | 说明 |
|---|---|---|
id | bigint | 漫画 ID |
title | text | 标题 |
pinyin_name | text | 拼音名 |
aliases | jsonb | 别名数组 |
slug | text | URL slug |
summary | text | 简介 |
cover_url | text | 封面 URL |
poster_url | text | 海报 URL |
category_id | bigint | 分类 ID |
lock_status | text | 锁定状态 |
rating_average | numeric | 平均评分 |
rating_count | integer | 评分人数 |
popularity_daily | integer | 日人气 |
popularity_weekly | integer | 周人气 |
popularity_monthly | integer | 月人气 |
is_finished | boolean | 是否完结 |
view_count | integer | 总浏览量 |
created_at | timestamptz | 创建时间 |
updated_at | timestamptz | 更新时间 |
categories | jsonb | 分类信息 {id, name, slug} |
chapters_count | bigint | 章节数 |
total_count | bigint | 符合条件的总记录数(用于分页) |
调用示例
// 搜索 "海贼",第 1 页,每页 20 条
val result = supabase.postgrest
.rpc("search_comics_pgroonga") {
parameter("search_term", "海贼")
parameter("page_number", 1)
parameter("items_per_page", 20)
}
.decodeList<ComicSearchResult>()
// 浏览模式:搜索词为空,按分类筛选 + 按人气排序
val browse = supabase.postgrest
.rpc("search_comics_pgroonga") {
parameter("search_term", "")
parameter("filter_category_id", 3)
parameter("sort_by", "popularity_weekly")
parameter("sort_order", "desc")
}
.decodeList<ComicSearchResult>()// 搜索 "海贼"
const { data } = await supabase
.rpc('search_comics_pgroonga', {
search_term: '海贼',
page_number: 1,
items_per_page: 20,
})
// 浏览模式:按分类筛选 + 按人气排序
const { data: browse } = await supabase
.rpc('search_comics_pgroonga', {
search_term: '',
filter_category_id: 3,
sort_by: 'popularity_weekly',
sort_order: 'desc',
})行为说明
- 搜索词为空时:不做全文匹配,仅应用筛选条件和排序,相当于带筛选的浏览列表
- 搜索匹配范围:
title、pinyin_name、aliases(JSONB 数组通过jsonb_array_to_text转为文本后拼接) total_count:每行都会携带总数,客户端取第一行的值即可用于分页计算categories:通过 LEFT JOINcategories表内联返回,无需额外查询
get_random_comics
随机返回指定数量的漫画,用于搜索页"随便看看"板块。支持按分类筛选和排除指定漫画。
参数
Prop
Type
p_limit 必须在 1–100 之间,超出范围会抛出异常。
返回字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | bigint | 漫画 ID |
title | text | 标题 |
summary | text | 简介 |
cover_url | text | 封面 URL |
poster_url | text | 海报 URL |
lock_status | text | 锁定状态 |
category_id | bigint | 分类 ID |
rating_average | numeric | 平均评分 |
popularity_daily | integer | 日人气 |
popularity_weekly | integer | 周人气 |
popularity_monthly | integer | 月人气 |
view_count | integer | 总浏览量 |
created_at | timestamptz | 创建时间 |
updated_at | timestamptz | 更新时间 |
调用示例
// 随机获取 6 条漫画
val random = supabase.postgrest
.rpc("get_random_comics") {
parameter("p_limit", 6)
}
.decodeList<ComicBrief>()
// 随机获取同分类漫画,排除当前漫画
val related = supabase.postgrest
.rpc("get_random_comics") {
parameter("p_limit", 6)
parameter("p_category_id", currentCategoryId)
parameter("p_exclude_comic_id", currentComicId)
}
.decodeList<ComicBrief>()// 随机获取 6 条漫画
const { data } = await supabase
.rpc('get_random_comics', { p_limit: 6 })
// 随机获取同分类漫画,排除当前漫画
const { data: related } = await supabase
.rpc('get_random_comics', {
p_limit: 6,
p_category_id: currentCategoryId,
p_exclude_comic_id: currentComicId,
})行为说明
- 使用
ORDER BY random()实现随机,每次调用结果不同 p_exclude_comic_id常用于漫画详情页的"相关推荐"场景,避免推荐当前正在看的漫画