按照匹配度排序
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -27,3 +27,4 @@ venv/
 | 
				
			|||||||
.env
 | 
					.env
 | 
				
			||||||
.env.example
 | 
					.env.example
 | 
				
			||||||
main
 | 
					main
 | 
				
			||||||
 | 
					.vscode
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +0,0 @@
 | 
				
			|||||||
{
 | 
					 | 
				
			||||||
    "editor.inlineSuggest.showToolbar": "always"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,7 +1,6 @@
 | 
				
			|||||||
package api
 | 
					package api
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
					 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -265,8 +264,6 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
				// 特殊处理 text 参数
 | 
									// 特殊处理 text 参数
 | 
				
			||||||
				var id_list []string
 | 
									var id_list []string
 | 
				
			||||||
				if args.Text != "" {
 | 
									if args.Text != "" {
 | 
				
			||||||
					fmt.Println("args:", args)
 | 
					 | 
				
			||||||
					//id_list = models.ElasticsearchSearch(args.Text).GetIDList(args.First, args.Last, args.After, args.Before)
 | 
					 | 
				
			||||||
					resp, err := models.ZincSearch(map[string]interface{}{
 | 
										resp, err := models.ZincSearch(map[string]interface{}{
 | 
				
			||||||
						"query": map[string]interface{}{
 | 
											"query": map[string]interface{}{
 | 
				
			||||||
							"bool": map[string]interface{}{
 | 
												"bool": map[string]interface{}{
 | 
				
			||||||
@@ -277,20 +274,17 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
								},
 | 
													},
 | 
				
			||||||
							},
 | 
												},
 | 
				
			||||||
						},
 | 
											},
 | 
				
			||||||
						"sort": []string{},
 | 
											"sort": []string{
 | 
				
			||||||
 | 
												"_score",
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
						"from": 0,
 | 
											"from": 0,
 | 
				
			||||||
						"size": 10,
 | 
											"size": 200,
 | 
				
			||||||
					})
 | 
										})
 | 
				
			||||||
					if err != nil {
 | 
										if err != nil {
 | 
				
			||||||
						fmt.Println("ZincSearch 获取图像列表失败", err)
 | 
											fmt.Println("ZincSearch 获取图像列表失败", err)
 | 
				
			||||||
						return nil, 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)
 | 
										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)), ","), "[]")
 | 
										id_list_str := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(id_list)), ","), "[]")
 | 
				
			||||||
					if id_list_str == "" {
 | 
										if id_list_str == "" {
 | 
				
			||||||
						return map[string]interface{}{
 | 
											return map[string]interface{}{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,7 +65,6 @@ type Response struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (res Response) ToIDList(first, last int, after, before string) (id_list []string) {
 | 
					func (res Response) ToIDList(first, last int, after, before string) (id_list []string) {
 | 
				
			||||||
	for _, hit := range res.Hits.Hits {
 | 
						for _, hit := range res.Hits.Hits {
 | 
				
			||||||
		fmt.Println(hit)
 | 
					 | 
				
			||||||
		id_list = append(id_list, hit.ID)
 | 
							id_list = append(id_list, hit.ID)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user