From f63d037b2c368e37689c0dcc03bfcf5ca6dc176f Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Mon, 19 Oct 2026 10:01:20 +0800 Subject: [PATCH] =?UTF-8?q?PostgreSQL=20=E4=B8=8A=E5=92=8C=20SQLite=20?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E7=9A=84=E4=B8=A4=E5=A4=84=EF=BC=9A=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=BA=93=E7=BB=9F=E8=AE=A1=E7=9A=84=20sum=20=E8=BD=AC?= =?UTF-8?q?=E6=88=90=E6=95=B4=E6=95=B0=EF=BC=88PostgreSQL=20=E7=9A=84=20su?= =?UTF-8?q?m=20=E4=BA=A4=E5=9B=9E=20numeric=EF=BC=8C=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E7=BB=99=20Decimal=EF=BC=89=EF=BC=9B=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E6=8C=89=E6=B3=A8=E9=87=8A=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=B8=8D=E5=88=86=E5=A4=A7=E5=B0=8F=E5=86=99=EF=BC=88SQLite=20?= =?UTF-8?q?=E7=9A=84=20LIKE=20=E5=AF=B9=20ASCII=20=E6=9C=AC=E6=9D=A5?= =?UTF-8?q?=E5=B0=B1=E4=B8=8D=E5=88=86=EF=BC=8CPostgreSQL=20=E5=88=86?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E7=94=A8=20icontains=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/data/source_objects.py | 3 ++- backend/app/memory/kb.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/app/data/source_objects.py b/backend/app/data/source_objects.py index b938a7d4..65d78ee5 100644 --- a/backend/app/data/source_objects.py +++ b/backend/app/data/source_objects.py @@ -886,8 +886,9 @@ async def search_index(session: AsyncSession, row: Any, query: str, *, limit: in return [], 0 key = name_key(text.rsplit(".", 1)[-1]) filt = (*_scope_filter(row.id, index_schema(row)), SourceObject.removed_at.is_(None), + # 名字比的是 name_key(ASCII 已转小写);注释要不分大小写:SQLite 的 LIKE 本来就不分(ASCII),PostgreSQL 分 or_(SourceObject.name_key.contains(key, autoescape=True), - SourceObject.comment.contains(text, autoescape=True))) + SourceObject.comment.icontains(text, autoescape=True))) total = int((await session.execute(select(func.count()).select_from(SourceObject).where(*filt))).scalar() or 0) rows = (await session.execute( select(SourceObject.name, SourceObject.name_key, SourceObject.kind, SourceObject.comment, diff --git a/backend/app/memory/kb.py b/backend/app/memory/kb.py index a324d973..9c976e63 100644 --- a/backend/app/memory/kb.py +++ b/backend/app/memory/kb.py @@ -399,7 +399,8 @@ async def list_collections(session: AsyncSession) -> list[dict[str, Any]]: func.sum(Document.chunk_count), ).group_by(Document.collection) ) + # sum 在 PostgreSQL 上给的是 numeric(驱动交回 Decimal),SQLite 给整数:一律转成 int return [ - {"collection": name, "documents": docs, "chunks": chunks or 0} + {"collection": name, "documents": int(docs), "chunks": int(chunks or 0)} for name, docs, chunks in rows ]