feat(ticket): 列表支持按标题/正文搜索
手机端工单列表要能像任务、知识一样搜。与知识列表同一套 ilike 匹配,标题记不清时正文关键词也能命中;补测试覆盖标题命中、正文命中、无结果三种情况。
This commit is contained in:
@@ -601,6 +601,7 @@ async def list_tickets(
|
||||
session: SessionDep,
|
||||
role: Annotated[str, Query(description="assigned|requested|all")] = "assigned",
|
||||
status: Annotated[list[str] | None, Query(description="按状态过滤,可重复")] = None,
|
||||
q: Annotated[str | None, Query(description="搜标题或正文")] = None,
|
||||
limit: Annotated[int, Query(ge=1, le=100)] = 20,
|
||||
cursor: Annotated[str | None, Query()] = None,
|
||||
) -> dict:
|
||||
@@ -622,6 +623,11 @@ async def list_tickets(
|
||||
if status:
|
||||
stmt = stmt.where(Item.status.in_(status))
|
||||
|
||||
if q and q.strip():
|
||||
# 与知识列表同一套模糊匹配:手机上找一张单,标题记不清时正文里的关键词也能命中
|
||||
like = f"%{q.strip()}%"
|
||||
stmt = stmt.where(or_(Item.title.ilike(like), Item.body_md.ilike(like)))
|
||||
|
||||
stmt = stmt.order_by(Item.updated_at.desc(), Item.id.desc()).limit(limit + 1)
|
||||
if parsed_cursor is not None:
|
||||
stmt = stmt.where(
|
||||
|
||||
Reference in New Issue
Block a user