游标修正
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package api
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"strings"
 | 
			
		||||
@@ -191,16 +192,16 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
				"update_time":   &graphql.ArgumentConfig{Type: graphql.DateTime},
 | 
			
		||||
				"first":         &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)"},
 | 
			
		||||
				"last":          &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的最後n個元素)"},
 | 
			
		||||
				"after":         &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中指定遊標之後的元素)"},
 | 
			
		||||
				"before":        &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中指定遊標之前的元素)"},
 | 
			
		||||
				"after":         &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之後的元素)"},
 | 
			
		||||
				"before":        &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之前的元素)"},
 | 
			
		||||
			},
 | 
			
		||||
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
 | 
			
		||||
				// 定义参数结构体
 | 
			
		||||
				var args struct {
 | 
			
		||||
					First  int
 | 
			
		||||
					Last   int
 | 
			
		||||
					After  int
 | 
			
		||||
					Before int
 | 
			
		||||
					After  string
 | 
			
		||||
					Before string
 | 
			
		||||
					Text   string
 | 
			
		||||
				}
 | 
			
		||||
				mapstructure.Decode(p.Args, &args)
 | 
			
		||||
@@ -273,7 +274,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
							"bool": map[string]interface{}{
 | 
			
		||||
								"must": []map[string]interface{}{
 | 
			
		||||
									{
 | 
			
		||||
										"query_string": map[string]string{"query": "content:" + args.Text},
 | 
			
		||||
										"query_string": map[string]string{"query": "City:" + args.Text},
 | 
			
		||||
									},
 | 
			
		||||
								},
 | 
			
		||||
							},
 | 
			
		||||
@@ -283,10 +284,14 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
						"size": 10,
 | 
			
		||||
					})
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						fmt.Println("获取图像列表失败", err)
 | 
			
		||||
						fmt.Println("ZincSearch 获取图像列表失败", err)
 | 
			
		||||
						return nil, err
 | 
			
		||||
					}
 | 
			
		||||
					// 格式化为带缩进的JSON打印
 | 
			
		||||
					data, _ := json.MarshalIndent(resp, "", "  ")
 | 
			
		||||
					fmt.Println("JSON", string(data))
 | 
			
		||||
					id_list = resp.ToIDList(args.First, args.Last, args.After, args.Before)
 | 
			
		||||
					fmt.Println("id_list:", id_list)
 | 
			
		||||
 | 
			
		||||
					id_list_str := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(id_list)), ","), "[]")
 | 
			
		||||
					if id_list_str == "" {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user