fix(web): up list search matches up name only, not video titles
This commit is contained in:
1 parent
a6bd910d9d
commit
003e65086e
2 files changed
+26
-2
No files matched your search
@@ -46,6 +46,8 @@ UP_SORTS = {
|
|||||||
"views", "count", "avg_views", "interaction", "avg_interaction", "latest",
|
"views", "count", "avg_views", "interaction", "avg_interaction", "latest",
|
||||||
"efficiency", "interaction_efficiency", "duration",
|
"efficiency", "interaction_efficiency", "duration",
|
||||||
}
|
}
|
||||||
|
# 搜索字段白名单:视频搜索匹配标题或 UP 名,UP 搜索只匹配 UP 名。
|
||||||
|
_Q_FIELDS = {"title": "v.title", "up_name": "v.up_name"}
|
||||||
CAPACITY = 1000
|
CAPACITY = 1000
|
||||||
CAPACITY_WARNING = 950
|
CAPACITY_WARNING = 950
|
||||||
TRACK_FANS_NAMES = {37754047: "咻咻满"}
|
TRACK_FANS_NAMES = {37754047: "咻咻满"}
|
||||||
@@ -284,6 +286,7 @@ class DashboardQueries:
|
|||||||
statuses: Sequence[str] = TRACKED_STATUSES,
|
statuses: Sequence[str] = TRACKED_STATUSES,
|
||||||
folder_id: int | None = None,
|
folder_id: int | None = None,
|
||||||
q: str | None = None,
|
q: str | None = None,
|
||||||
|
q_fields: Sequence[str] | None = None,
|
||||||
within_field: str | None = None,
|
within_field: str | None = None,
|
||||||
within_start: str | None = None,
|
within_start: str | None = None,
|
||||||
within_end: str | None = None,
|
within_end: str | None = None,
|
||||||
@@ -299,10 +302,17 @@ class DashboardQueries:
|
|||||||
params.append(int(up_mid))
|
params.append(int(up_mid))
|
||||||
if q:
|
if q:
|
||||||
pattern = _like_pattern(q)
|
pattern = _like_pattern(q)
|
||||||
|
fields = tuple(q_fields) if q_fields else ("title", "up_name")
|
||||||
|
columns = []
|
||||||
|
for field in fields:
|
||||||
|
column = _Q_FIELDS.get(field)
|
||||||
|
if column is None:
|
||||||
|
raise ValueError(f"不支持的搜索字段: {field}")
|
||||||
|
columns.append(column)
|
||||||
clauses.append(
|
clauses.append(
|
||||||
"(v.title LIKE ? ESCAPE '\\' OR v.up_name LIKE ? ESCAPE '\\')"
|
"(" + " OR ".join(f"{col} LIKE ? ESCAPE '\\'" for col in columns) + ")"
|
||||||
)
|
)
|
||||||
params.extend([pattern, pattern])
|
params.extend([pattern] * len(columns))
|
||||||
if within_field:
|
if within_field:
|
||||||
if within_field not in {"pubdate", "first_seen"}:
|
if within_field not in {"pubdate", "first_seen"}:
|
||||||
raise ValueError("within_field 必须是 pubdate 或 first_seen")
|
raise ValueError("within_field 必须是 pubdate 或 first_seen")
|
||||||
@@ -1060,6 +1070,7 @@ class DashboardQueries:
|
|||||||
videos = self._videos(
|
videos = self._videos(
|
||||||
conn,
|
conn,
|
||||||
q=q,
|
q=q,
|
||||||
|
q_fields=("up_name",) if q else None,
|
||||||
within_field=within_field,
|
within_field=within_field,
|
||||||
within_start=within_start,
|
within_start=within_start,
|
||||||
within_end=within_end,
|
within_end=within_end,
|
||||||
|
|||||||
@@ -203,6 +203,19 @@ def test_up_queries():
|
|||||||
assert blacklisted["blacklisted"] is True
|
assert blacklisted["blacklisted"] is True
|
||||||
assert blacklisted["video_count"] == 1
|
assert blacklisted["video_count"] == 1
|
||||||
assert q.up_detail(999999) is None
|
assert q.up_detail(999999) is None
|
||||||
|
|
||||||
|
# UP 搜索只匹配 UP 名,不匹配视频标题
|
||||||
|
title_only = q.list_ups(q="视频")
|
||||||
|
assert title_only["total"] == 0
|
||||||
|
name_match = q.list_ups(q="UP A")
|
||||||
|
assert name_match["total"] == 1
|
||||||
|
assert name_match["items"][0]["up_mid"] == 1
|
||||||
|
assert name_match["items"][0]["video_count"] == 2
|
||||||
|
# 大小写不敏感
|
||||||
|
lower = q.list_ups(q="up b")
|
||||||
|
assert lower["total"] == 1 and lower["items"][0]["up_mid"] == 2
|
||||||
|
# 命中多个 UP
|
||||||
|
assert q.list_ups(q="UP")["total"] == 2
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user