按照匹配度排序
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,3 +27,4 @@ venv/
|
||||
.env
|
||||
.env.example
|
||||
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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
@@ -265,8 +264,6 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
||||
// 特殊处理 text 参数
|
||||
var id_list []string
|
||||
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{}{
|
||||
"query": 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,
|
||||
"size": 10,
|
||||
"size": 200,
|
||||
})
|
||||
if err != nil {
|
||||
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 == "" {
|
||||
return map[string]interface{}{
|
||||
|
@@ -65,7 +65,6 @@ type Response struct {
|
||||
|
||||
func (res Response) ToIDList(first, last int, after, before string) (id_list []string) {
|
||||
for _, hit := range res.Hits.Hits {
|
||||
fmt.Println(hit)
|
||||
id_list = append(id_list, hit.ID)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user