OCR 搜索按上传时间倒序
This commit is contained in:
		@@ -90,19 +90,17 @@ func PutPraises(page int) error {
 | 
				
			|||||||
// 同步收藏数据
 | 
					// 同步收藏数据
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取推荐ID
 | 
					// 获取推荐ID
 | 
				
			||||||
func GetRecommend(user_id int, category string) ([]int, error) {
 | 
					func GetRecommend(user_id int, categorys []string) ([]int, error) {
 | 
				
			||||||
	var ctx context.Context = context.Background()
 | 
						var ctx context.Context = context.Background()
 | 
				
			||||||
	var ids []int
 | 
						var ids []int
 | 
				
			||||||
 | 
						data, err := gorse.GetItemRecommend(ctx, fmt.Sprintf("%d", user_id), categorys, "read", "0", 100, 0)
 | 
				
			||||||
	data, err := gorse.GetItemLatestWithCategory(ctx, fmt.Sprintf("%d", user_id), category, 100, 0)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		fmt.Println("获取推荐失败", err)
 | 
							fmt.Println("获取推荐失败", err)
 | 
				
			||||||
		return ids, err
 | 
							return ids, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, item := range data {
 | 
						for _, item := range data {
 | 
				
			||||||
		id, _ := strconv.Atoi(item.Id)
 | 
							id, _ := strconv.Atoi(item)
 | 
				
			||||||
		ids = append(ids, id)
 | 
							ids = append(ids, id)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	return ids, nil
 | 
						return ids, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -583,7 +583,6 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
							"bool": map[string]interface{}{
 | 
												"bool": map[string]interface{}{
 | 
				
			||||||
								"must": []map[string]interface{}{
 | 
													"must": []map[string]interface{}{
 | 
				
			||||||
									{
 | 
														{
 | 
				
			||||||
										//"query_string": map[string]string{"query": "text:" + args.Text},
 | 
					 | 
				
			||||||
										"match_phrase": map[string]string{"text": args.Text},
 | 
															"match_phrase": map[string]string{"text": args.Text},
 | 
				
			||||||
									},
 | 
														},
 | 
				
			||||||
								},
 | 
													},
 | 
				
			||||||
@@ -592,8 +591,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
						"sort": []string{
 | 
											"sort": []string{
 | 
				
			||||||
							"_score",
 | 
												"_score",
 | 
				
			||||||
						},
 | 
											},
 | 
				
			||||||
						//"from": 0,
 | 
											"size": 2000,
 | 
				
			||||||
						"size": 1000,
 | 
					 | 
				
			||||||
					})
 | 
										})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if err != nil {
 | 
										if err != nil {
 | 
				
			||||||
@@ -613,7 +611,8 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					query = query.Where(goqu.Ex{"web_images.id": goqu.Op{"in": item}}).Select("web_images.id", goqu.L(
 | 
										query = query.Where(goqu.Ex{"web_images.id": goqu.Op{"in": item}}).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(item)), ", "), "")),
 | 
											//fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY FIELD(%s, %s))", "web_images.id", regexp.MustCompile(`[\[\]]`).ReplaceAllString(strings.Join(strings.Fields(fmt.Sprint(item)), ", "), "")),
 | 
				
			||||||
 | 
											fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY %s %s)", "web_images.id", "DESC"),
 | 
				
			||||||
					).As("row_num"))
 | 
										).As("row_num"))
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -637,7 +636,9 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
				if p.Args["interest"] != nil {
 | 
									if p.Args["interest"] != nil {
 | 
				
			||||||
					fmt.Println("interest:", p.Args["interest"])
 | 
										fmt.Println("interest:", p.Args["interest"])
 | 
				
			||||||
					user_id := p.Args["interest"].(int)
 | 
										user_id := p.Args["interest"].(int)
 | 
				
			||||||
					list, err := GetRecommend(user_id, "image")
 | 
										fmt.Println("interest1:", user_id)
 | 
				
			||||||
 | 
										list, err := GetRecommend(user_id, []string{})
 | 
				
			||||||
 | 
										fmt.Println("interest2:", list, err)
 | 
				
			||||||
					if err != nil {
 | 
										if err != nil {
 | 
				
			||||||
						fmt.Println("GetRecommend 获取兴趣推荐失败", err)
 | 
											fmt.Println("GetRecommend 获取兴趣推荐失败", err)
 | 
				
			||||||
						return map[string]interface{}{"list": []Image{}, "total": 0}, nil
 | 
											return map[string]interface{}{"list": []Image{}, "total": 0}, nil
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user