Browse Source

feat:新增es工具类

wangchuanjin 2 years ago
parent
commit
250ddbda70
1 changed files with 93 additions and 2 deletions
  1. 93 2
      es/es.go

+ 93 - 2
es/es.go

@@ -65,8 +65,11 @@ type Es interface {
 	GetResForJYView(index, itype string, keys []KeyConfig, allquery, findfields, SortQuery, fields string, start, limit int) *[]map[string]interface{}
 }
 
-var SR = strings.Replace
-var filterQuery string
+var (
+	filterQuery string
+	SR          = strings.Replace
+	VarEs       Es
+)
 
 type KeyConfig struct {
 	Keys      []string `json:"key"`
@@ -144,5 +147,93 @@ func NewEs(version, address string, size int, userName, password string) Es {
 		}
 	}
 	es.Init()
+	VarEs = es
 	return es
 }
+func Save(index, itype string, obj interface{}) bool {
+	return VarEs.Save(index, itype, obj)
+}
+func GetBySearchType(index, searchType, query string) (int64, *[]map[string]interface{}) {
+	return VarEs.GetBySearchType(index, searchType, query)
+}
+func Get(index, itype, query string) *[]map[string]interface{} {
+	return VarEs.Get(index, itype, query)
+}
+func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
+	return VarEs.GetOA(index, itype, query)
+}
+func GetNoLimit(index, itype, query string) *[]map[string]interface{} {
+	return VarEs.GetNoLimit(index, itype, query)
+}
+func GetPage(index, itype, query, order, field string, start, limit int) *[]map[string]interface{} {
+	return VarEs.GetPage(index, itype, query, order, field, start, limit)
+}
+func GetOAPage(index, itype, query, order, field string, start, limit int) (*[]map[string]interface{}, int) {
+	return VarEs.GetOAPage(index, itype, query, order, field, start, limit)
+}
+func MakeQuery(query, order, fileds string, start, limit int) string {
+	return VarEs.MakeQuery(query, order, fileds, start, limit)
+}
+func AnalyQuery(query interface{}, parent string, result string) string {
+	return VarEs.AnalyQuery(query, parent, result)
+}
+func GetByIdField(index, itype, id, fields string) *map[string]interface{} {
+	return VarEs.GetByIdField(index, itype, id, fields)
+}
+func GetById(index, itype string, ids ...string) *[]map[string]interface{} {
+	return VarEs.GetById(index, itype, ids...)
+}
+func Update(index, itype, id string, updateStr string) bool {
+	return VarEs.Update(index, itype, id, updateStr)
+}
+func BulkUpdate(index, itype string, ids []string, updateStr string) {
+	VarEs.BulkUpdate(index, itype, ids, updateStr)
+}
+func NewBulkUpdate(index string, params ...[]string) bool {
+	return VarEs.NewBulkUpdate(index, params...)
+}
+func DelById(index, itype, id string) bool {
+	return VarEs.DelById(index, itype, id)
+}
+func UpdateNewDoc(index, itype string, obj ...interface{}) bool {
+	return VarEs.UpdateNewDoc(index, itype, obj...)
+}
+func BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
+	VarEs.BulkSave(index, itype, obj, isDelBefore)
+}
+func Count(index, itype string, query interface{}) int64 {
+	return VarEs.Count(index, itype, query)
+}
+func GetNgramQuery(query interface{}, mustquery, findfields string) (qstr string) {
+	return VarEs.GetNgramQuery(query, mustquery, findfields)
+}
+func GetNgramQuery_New(querystring, querymust interface{}, must, findfields string) (qstring string) {
+	return VarEs.GetNgramQuery_New(querystring, querymust, must, findfields)
+}
+func GetByNgram(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int) *[]map[string]interface{} {
+	return VarEs.GetByNgram(index, itype, query, mustquery, findfields, order, fields, start, limit)
+}
+func GetByNgramOther(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool, count int) *[]map[string]interface{} {
+	return VarEs.GetByNgramOther(index, itype, query, mustquery, findfields, order, fields, start, limit, highlight, filtermode, count)
+}
+func GetByNgramAll(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
+	return VarEs.GetByNgramAll(index, itype, query, mustquery, findfields, order, fields, start, limit, highlight, filtermode)
+}
+func GetByNgramAll_New(index, itype string, querystring, querymust interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
+	return VarEs.GetByNgramAll_New(index, itype, querystring, querymust, mustquery, findfields, order, fields, start, limit, highlight, filtermode)
+}
+func GetResForJY(index, itype string, keys []KeyConfig, allquery, findfields, SortQuery, fields string, start, limit int) *[]map[string]interface{} {
+	return VarEs.GetResForJY(index, itype, keys, allquery, findfields, SortQuery, fields, start, limit)
+}
+func GetAllByNgram(index, itype, qstr, findfields, order, fields string, start, limit, count int, highlight bool) *[]map[string]interface{} {
+	return VarEs.GetAllByNgram(index, itype, qstr, findfields, order, fields, start, limit, count, highlight)
+}
+func GetAllByNgram_MP(index, itype, qstr, findfields, order, fields string, start, limit, count int, highlight bool) *[]map[string]interface{} {
+	return VarEs.GetAllByNgram_MP(index, itype, qstr, findfields, order, fields, start, limit, count, highlight)
+}
+func GetAllByIk(index, itype, qstr, findfields, order, fields string, start, limit, count int, highlight bool) *[]map[string]interface{} {
+	return VarEs.GetAllByIk(index, itype, qstr, findfields, order, fields, start, limit, count, highlight)
+}
+func GetResForJYView(index, itype string, keys []KeyConfig, allquery, findfields, SortQuery, fields string, start, limit int) *[]map[string]interface{} {
+	return VarEs.GetResForJYView(index, itype, keys, allquery, findfields, SortQuery, fields, start, limit)
+}