使用配置文件和生产索引

This commit is contained in:
2023-12-08 23:20:11 +08:00
parent b4ce9846bf
commit e5017fdcdb
4 changed files with 16 additions and 29 deletions

View File

@@ -1,3 +1,3 @@
{ {
"editor.inlineSuggest.showToolbar": "onHover" "editor.inlineSuggest.showToolbar": "always"
} }

View File

@@ -272,7 +272,7 @@ 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": "City:" + args.Text}, "query_string": map[string]string{"query": "text:" + args.Text},
}, },
}, },
}, },

View File

@@ -182,6 +182,7 @@ func main() {
config := viper.GetViper() config := viper.GetViper()
models.InitConfig(config) models.InitConfig(config)
models.ZincInit()
mysqlConnection.Init() mysqlConnection.Init()
milvusConnection.Init() milvusConnection.Init()

View File

@@ -11,21 +11,19 @@ import (
"net/url" "net/url"
) )
// 查询参数 var (
//type Query struct { user string
// Query struct { password string
// Bool struct { index string
// Must []struct { zincHost string
// QueryString struct { )
// Query string `json:"query"`
// } `json:"query_string"` func ZincInit() {
// } `json:"must"` user = config.GetString("zincsearch.user")
// } `json:"bool"` password = config.GetString("zincsearch.password")
// } `json:"query"` index = config.GetString("zincsearch.index")
// Sort []string `json:"sort"` zincHost = config.GetString("zincsearch.host")
// From int `json:"from"` }
// Size int `json:"size"`
//}
// 返回结果 // 返回结果
type Response struct { type Response struct {
@@ -111,12 +109,6 @@ func (res Response) ToIDList(first, last int, after, before string) (id_list []s
} }
func ZincSearch(query map[string]interface{}) (rest Response, err error) { func ZincSearch(query map[string]interface{}) (rest Response, err error) {
const (
user = "admin"
password = "Complexpass#123"
index = "olympics"
zincHost = "https://zincsearch.gameui.net"
)
bas64encodedCreds := base64.StdEncoding.EncodeToString([]byte(user + ":" + password)) bas64encodedCreds := base64.StdEncoding.EncodeToString([]byte(user + ":" + password))
zincURL := zincHost + "/es/" + index + "/_search" zincURL := zincHost + "/es/" + index + "/_search"
queryBytes, _ := json.Marshal(query) queryBytes, _ := json.Marshal(query)
@@ -159,12 +151,6 @@ func ZincSearch(query map[string]interface{}) (rest Response, err error) {
} }
func ZincPut(data map[string]interface{}) (err error) { func ZincPut(data map[string]interface{}) (err error) {
const (
user = "admin"
password = "Complexpass#123"
index = "olympics"
zincHost = "https://zincsearch.gameui.net"
)
bas64encodedCreds := base64.StdEncoding.EncodeToString([]byte(user + ":" + password)) bas64encodedCreds := base64.StdEncoding.EncodeToString([]byte(user + ":" + password))
zincURL := zincHost + "/api/" + index + "/_doc" zincURL := zincHost + "/api/" + index + "/_doc"
queryBytes, _ := json.Marshal(data) queryBytes, _ := json.Marshal(data)