Revert^2 "feat: 完整集成JWLLL搜索推荐系统到Merge项目"
This reverts commit 8c2ae427041141a7dfc6f7b1ca1a16e713003130.
Reason for revert: <回退功能,command由jwl实现>
Change-Id: I08cf7f6de082d6a837aa3e59f68787dbf9d4d1e1
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