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:
@@ -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),
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user