feat: 完整集成JWLLL搜索推荐系统到Merge项目
新增功能:
- 完整的JWLLL搜索推荐后端服务 (back_jwlll/)
- 前端智能搜索和推荐功能集成
- HomeFeed组件增强: 数据源切换(原始数据 ↔ 智能推荐)
- 新增PostDetailJWLLL和UploadPageJWLLL组件
- 新增search_jwlll.js API接口
技术特性:
- 标签推荐和协同过滤推荐算法
- 中文分词和Word2Vec语义搜索
- 100%向后兼容,原功能完全保留
- 独立服务架构,无冲突部署
集成内容:
- JWLLL后端服务配置和依赖
- 前端路由和组件更新
- 样式文件和API集成
- 项目文档和启动工具
Change-Id: I1d008cf04eee40e7d81bfb9109f933d3447d1760
diff --git a/Merge/front/src/api/search_jwlll.js b/Merge/front/src/api/search_jwlll.js
new file mode 100644
index 0000000..5ab7eb1
--- /dev/null
+++ b/Merge/front/src/api/search_jwlll.js
@@ -0,0 +1,97 @@
+// 搜索推荐算法相关的API接口
+// 对应 JWLLL 后端服务
+
+const BASE_URL = 'http://127.0.0.1:5000'
+
+// 通用请求函数
+const request = async (url, options = {}) => {
+ try {
+ const response = await fetch(url, {
+ headers: {
+ 'Content-Type': 'application/json',
+ ...options.headers
+ },
+ ...options
+ })
+ return await response.json()
+ } catch (error) {
+ console.error('API请求错误:', error)
+ throw error
+ }
+}
+
+// 搜索API
+export const searchAPI = {
+ // 搜索内容
+ search: async (keyword, category = undefined) => {
+ return await request(`${BASE_URL}/search`, {
+ method: 'POST',
+ body: JSON.stringify({ keyword, category })
+ })
+ },
+
+ // 获取用户标签
+ getUserTags: async (userId) => {
+ return await request(`${BASE_URL}/user_tags?user_id=${userId}`)
+ },
+
+ // 标签推荐
+ recommendByTags: async (userId, tags) => {
+ return await request(`${BASE_URL}/recommend_tags`, {
+ method: 'POST',
+ body: JSON.stringify({ user_id: userId, tags })
+ })
+ },
+
+ // 协同过滤推荐
+ userBasedRecommend: async (userId, topN = 20) => {
+ return await request(`${BASE_URL}/user_based_recommend`, {
+ method: 'POST',
+ body: JSON.stringify({ user_id: userId, top_n: topN })
+ })
+ },
+
+ // 获取帖子详情
+ getPostDetail: async (postId) => {
+ return await request(`${BASE_URL}/post/${postId}`)
+ },
+
+ // 点赞帖子
+ likePost: async (postId, userId) => {
+ return await request(`${BASE_URL}/like`, {
+ method: 'POST',
+ body: JSON.stringify({ post_id: postId, user_id: userId })
+ })
+ },
+
+ // 取消点赞
+ unlikePost: async (postId, userId) => {
+ return await request(`${BASE_URL}/unlike`, {
+ method: 'POST',
+ body: JSON.stringify({ post_id: postId, user_id: userId })
+ })
+ },
+
+ // 添加评论
+ addComment: async (postId, userId, content) => {
+ return await request(`${BASE_URL}/comment`, {
+ method: 'POST',
+ body: JSON.stringify({ post_id: postId, user_id: userId, content })
+ })
+ },
+
+ // 获取评论
+ getComments: async (postId) => {
+ return await request(`${BASE_URL}/comments/${postId}`)
+ },
+
+ // 上传帖子
+ uploadPost: async (postData) => {
+ return await request(`${BASE_URL}/upload`, {
+ method: 'POST',
+ body: JSON.stringify(postData)
+ })
+ }
+}
+
+export default searchAPI