feat(knowledge): 文档列表新增按名称/作者的模糊搜索 - #1097
Merged
Merged
Conversation
在 Knowledge / Documents 页工具栏中央新增文档搜索框,支持按 文件名/显示名/ 作者姓名 大小写不敏感模糊检索,降低翻页查找的认知摩擦。端到端贯通四层: - storage/service.py:list_documents 新增 search 参数,名称维度 ILIKE original_filename/display_name;作者维度因 created_by 存 user_id 而非姓名, 经 user_states.state.profile.name 参数化 JSONB 子查询反解匹配(注入安全, 过滤条件并入共享 conditions 使 count 与分页自动一致); - knowledge/routes/documents.py:list_all_documents 与 list_documents 两端点 对称新增 search 查询参数并透传; - knowledge-api.ts:fetchAllDocuments 新增 search 参数并写入 query; - documents/page.tsx:镜像 EntityListPanel 范式,300ms 防抖输入即搜 + filters memo 驱动 useInfiniteList 自动 reset 回第 1 页 + lucide Search 图标搜索框 + 区分「无数据/搜索无结果」空状态文案; - BFF proxyGet 透传全部 query,无需改动; 测试:新增 3 个路由透传单测 + 5 个真库集成测试(覆盖名称/作者/空搜索/ 无命中/count 一致性)。实机回归验证搜索框渲染位置、search 参数透传、 深浅色对比度与清空恢复均正常。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
/knowledge/documents文档管理页此前工具栏仅有勾选提示与 Translate / Import 按钮,缺乏检索能力。随着文档数量增长(当前已 22 条、3 页并持续增加),用户只能逐页翻找目标文档,认知摩擦高。核心变更
storage/service.py:list_documents新增可选search参数。名称维度对original_filename/display_name做大小写不敏感 ILIKE;作者维度因created_by存的是不可见 user_id 而非姓名,经user_states.state.profile.name参数化 JSONB 子查询反解为 user_id 集合再过滤。过滤条件并入共享conditions,使 count 与分页自动一致。knowledge/routes/documents.py:list_all_documents(跨语料库,本页调用)与list_documents(按语料库)两端点对称新增search查询参数并透传。knowledge-api.ts:fetchAllDocuments新增search参数并写入 query string。documents/page.tsx:镜像姊妹组件EntityListPanel范式——300ms 防抖输入即搜、filtersmemo 驱动useInfiniteList自动 reset 回第 1 页、lucideSearch图标搜索框置于工具栏中央、区分「无数据 / 搜索无结果」空状态文案。_proxy.ts无需改动:proxyGet已透传全部 query string。风险与回滚
search全链路可选、默认不过滤,不传时行为与改动前完全一致;全程 SQLAlchemy 列表达式 +.astext.ilike()参数化,无 SQL 注入面;作者子查询命中小表user_states,无 N+1。注意:live 后端从主仓运行,需部署本分支后线上过滤才实际生效(未部署时前端优雅降级返回全量,不报错)。git revert本 PR 合并提交即可,无数据迁移、无 schema 变更,可安全回滚。验证证据
search正确传入存储层)。test_document_list_search.py),覆盖名称命中 / 作者姓名经user_states反解命中 / 空搜索等价全量 / 无命中 / count 与 items 一致性。test_api_documents.py全量 24 passed。?...&search=Attention+Is+All→ 200 确认参数透传,深/浅色模式对比度达标,清空恢复全量正常。tsc --noEmit、ESLint(--max-warnings=0)全部通过。影响范围
negentropy-ui文档页 + 客户端 API(新增能力,不改既有 Translate/Import/删除/心跳链路)。negentropy文档列表存储层 + 路由层(新增可选参数,向后兼容)。Next Best Action
created_by索引。