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 ]