feat: 重构 AI 搜索架构并优化用户体验

- 重构 AI 搜索数据流:n8n 只返回项目 ID,Next.js 后端负责组装完整数据
- 首页添加 AI 搜索功能,支持跳转到项目列表页后自动触发搜索
- 新增 HomeSearchBar 组件处理首页搜索逻辑
- 修复英文模式下搜索按钮重叠问题,使用 flex 布局确保间距
- 完善国际化支持,添加切换模式提示和加载状态的翻译
- 优化搜索体验:切换 AI/传统搜索模式时保留输入框内容

Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
This commit is contained in:
2026-01-27 16:40:44 +08:00
co-authored by Claude
parent 11009320f1
commit 660cd5168c
9 changed files with 285 additions and 41 deletions
+44
View File
@@ -181,3 +181,47 @@ export async function getTopTags(limit: number = 10): Promise<TagWithProjectCoun
})
.slice(0, limit)
}
// 定义 AI 搜索结果类型
export type AISearchResultItem = Omit<ProjectWithFlatTags, 'status'> & {
similarity: number
}
// n8n 返回的简化搜索结果类型
export type N8NSearchResult = {
id: string
similarity: number
}
/**
* 根据 ID 列表批量获取项目(用于 AI 搜索结果组装)
* @param ids 项目 ID 列表
* @returns 带有相似度分数的项目列表
*/
export async function getProjectsByIds(ids: string[]): Promise<ProjectWithFlatTags[]> {
if (ids.length === 0) {
return []
}
const projects = await prisma.project.findMany({
where: {
id: {
in: ids,
},
},
include: {
tags: {
include: {
tag: true,
},
},
links: true,
},
})
// Transform tags to flatten the structure
return projects.map((project) => ({
...project,
tags: project.tags.map((pt) => pt.tag),
}))
}