diff --git a/api/graphql.go b/api/graphql.go index 67cdacb..943664b 100644 --- a/api/graphql.go +++ b/api/graphql.go @@ -633,8 +633,22 @@ func NewSchema(config Config) (graphql.Schema, error) { ).As("row_num")) } + // 筛选:兴趣推荐 + if p.Args["interest"] != nil { + user_id := p.Args["interest"].(int) + list, err := GetRecommend(user_id, "image") + if err != nil { + fmt.Println("GetRecommend 获取兴趣推荐失败", err) + return nil, err + } + fmt.Println("Interest:", user_id, list) + query = query.Where(goqu.Ex{"web_images.id": goqu.Op{"in": list}}).Select("web_images.id", goqu.L( + fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY FIELD(%s, %s))", "web_images.id", regexp.MustCompile(`[\[\]]`).ReplaceAllString(strings.Join(strings.Fields(fmt.Sprint(list)), ", "), "")), + ).As("row_num")) + } + // 如果没有外部排序则使用指定排序(正则sort只能是字母数字下划下) - if p.Args["text"] == nil && p.Args["similar"] == nil { + if p.Args["text"] == nil && p.Args["similar"] == nil && p.Args["interest"] == nil { sort := regexp.MustCompile(`[^a-zA-Z0-9_]`).ReplaceAllString(p.Args["sort"].(string), "") order := regexp.MustCompile(`[^a-zA-Z0-9_]`).ReplaceAllString(p.Args["order"].(string), "") query = query.Select("web_images.id", goqu.L( @@ -642,11 +656,6 @@ func NewSchema(config Config) (graphql.Schema, error) { ).As("row_num")) } - // 筛选:兴趣推荐 - if args.Interest != 0 { - fmt.Println("Interest:", args.Interest) - } - // 筛选:时间段 applyTimeCondition := func(name string, str string) { parts := strings.Split(str, "-")