瀏覽代碼

初始化

wangchuanjin 5 年之前
父節點
當前提交
5aabbe2739
共有 3 個文件被更改,包括 18 次插入18 次删除
  1. 7 7
      src/qfw/util/elastic/elasticSim.go
  2. 8 8
      src/qfw/util/elastic/elasticutil.go
  3. 3 3
      src/qfw/util/elastic/util.go

+ 7 - 7
src/qfw/util/elastic/elasticSim.go

@@ -23,7 +23,7 @@ type Elastic struct {
 }
 }
 
 
 func (e *Elastic) InitElasticSize() {
 func (e *Elastic) InitElasticSize() {
-	defer Catch()
+	defer catch()
 	e.Pool = make(chan *es.Client, e.I_size)
 	e.Pool = make(chan *es.Client, e.I_size)
 	for _, s := range strings.Split(e.S_esurl, ",") {
 	for _, s := range strings.Split(e.S_esurl, ",") {
 		e.Addrs = append(e.Addrs, s)
 		e.Addrs = append(e.Addrs, s)
@@ -126,7 +126,7 @@ func (e *Elastic) Get(index, itype, query string) *[]map[string]interface{} {
 
 
 //关闭elastic
 //关闭elastic
 func (e *Elastic) Close() {
 func (e *Elastic) Close() {
-	defer Catch()
+	defer catch()
 	for i := 0; i < e.I_size; i++ {
 	for i := 0; i < e.I_size; i++ {
 		cli := <-e.Pool
 		cli := <-e.Pool
 		cli.Stop()
 		cli.Stop()
@@ -138,7 +138,7 @@ func (e *Elastic) Close() {
 
 
 //获取连接
 //获取连接
 //func (e *Elastic) GetEsConn() (c *es.Client) {
 //func (e *Elastic) GetEsConn() (c *es.Client) {
-//	defer Catch()
+//	defer catch()
 //	select {
 //	select {
 //	case c = <-e.Pool:
 //	case c = <-e.Pool:
 //		if c == nil || !c.IsRunning() {
 //		if c == nil || !c.IsRunning() {
@@ -159,7 +159,7 @@ func (e *Elastic) Close() {
 //}
 //}
 
 
 func (e *Elastic) BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
 func (e *Elastic) BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
-	defer Catch()
+	defer catch()
 	client := e.GetEsConn()
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
 	defer e.DestoryEsConn(client)
 	if client != nil {
 	if client != nil {
@@ -179,14 +179,14 @@ func (e *Elastic) BulkSave(index, itype string, obj *[]map[string]interface{}, i
 
 
 //先删除后增
 //先删除后增
 func (e *Elastic) UpdateNewDoc(index, itype string, obj ...interface{}) bool {
 func (e *Elastic) UpdateNewDoc(index, itype string, obj ...interface{}) bool {
-	defer Catch()
+	defer catch()
 	client := e.GetEsConn()
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
 	defer e.DestoryEsConn(client)
 	b := false
 	b := false
 	if client != nil {
 	if client != nil {
 		var err error
 		var err error
 		for _, v := range obj {
 		for _, v := range obj {
-			tempObj := ObjToMap(v)
+			tempObj := objToMap(v)
 			id := fmt.Sprintf("%v", (*tempObj)["_id"])
 			id := fmt.Sprintf("%v", (*tempObj)["_id"])
 			client.Delete().Index(index).Type(itype).Id(id).Do()
 			client.Delete().Index(index).Type(itype).Id(id).Do()
 			_, err = client.Index().Index(index).Type(itype).BodyJson(tempObj).Do()
 			_, err = client.Index().Index(index).Type(itype).BodyJson(tempObj).Do()
@@ -203,7 +203,7 @@ func (e *Elastic) UpdateNewDoc(index, itype string, obj ...interface{}) bool {
 
 
 //根据id删除索引对象
 //根据id删除索引对象
 func (e *Elastic) DelById(index, itype, id string) bool {
 func (e *Elastic) DelById(index, itype, id string) bool {
-	defer Catch()
+	defer catch()
 	client := e.GetEsConn()
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
 	defer e.DestoryEsConn(client)
 	b := false
 	b := false

+ 8 - 8
src/qfw/util/elastic/elasticutil.go

@@ -139,7 +139,7 @@ func Save(index, itype string, obj interface{}) bool {
 			}
 			}
 		}
 		}
 	}()
 	}()
-	_, err := client.Index().Index(index).Type(itype).BodyJson(ObjToMap(obj)).Do()
+	_, err := client.Index().Index(index).Type(itype).BodyJson(objToMap(obj)).Do()
 	if err != nil {
 	if err != nil {
 		log.Println("保存到ES出错", err.Error(), obj)
 		log.Println("保存到ES出错", err.Error(), obj)
 		return false
 		return false
@@ -627,7 +627,7 @@ func UpdateNewDoc(index, itype string, obj ...interface{}) bool {
 		}()
 		}()
 		var err error
 		var err error
 		for _, v := range obj {
 		for _, v := range obj {
-			tempObj := ObjToMap(v)
+			tempObj := objToMap(v)
 			id := fmt.Sprintf("%v", (*tempObj)["_id"])
 			id := fmt.Sprintf("%v", (*tempObj)["_id"])
 			client.Delete().Index(index).Type(itype).Id(id).Do()
 			client.Delete().Index(index).Type(itype).Id(id).Do()
 			_, err = client.Index().Index(index).Type(itype).BodyJson(tempObj).Do()
 			_, err = client.Index().Index(index).Type(itype).BodyJson(tempObj).Do()
@@ -961,7 +961,7 @@ func GetNgramQuery(query interface{}, mustquery, findfields string) (qstr string
 	} else if q, ok := query.([]string); ok {
 	} else if q, ok := query.([]string); ok {
 		words = q
 		words = q
 	} else if q, ok := query.([]interface{}); ok {
 	} else if q, ok := query.([]interface{}); ok {
-		words = ObjArrToStringArr(q)
+		words = objArrToStringArr(q)
 	}
 	}
 	if words != nil {
 	if words != nil {
 		new_minq := fmt.Sprintf(minq, "%s", findfields)
 		new_minq := fmt.Sprintf(minq, "%s", findfields)
@@ -992,7 +992,7 @@ func GetNgramQuery_New(querystring, querymust interface{}, must, findfields stri
 	} else if q, ok := querymust.([]string); ok {
 	} else if q, ok := querymust.([]string); ok {
 		wordsMust = q
 		wordsMust = q
 	} else if q, ok := querymust.([]interface{}); ok {
 	} else if q, ok := querymust.([]interface{}); ok {
-		wordsMust = ObjArrToStringArr(q)
+		wordsMust = objArrToStringArr(q)
 	}
 	}
 	if wordsMust != nil {
 	if wordsMust != nil {
 		new_minq := fmt.Sprintf(minq, "%s", findfields)
 		new_minq := fmt.Sprintf(minq, "%s", findfields)
@@ -1019,7 +1019,7 @@ func GetNgramQuery_New(querystring, querymust interface{}, must, findfields stri
 	} else if q, ok := querystring.([]string); ok {
 	} else if q, ok := querystring.([]string); ok {
 		querysShold = q
 		querysShold = q
 	} else if q, ok := querystring.([]interface{}); ok {
 	} else if q, ok := querystring.([]interface{}); ok {
-		querysShold = ObjArrToStringArr(q)
+		querysShold = objArrToStringArr(q)
 	}
 	}
 	if querysShold != nil {
 	if querysShold != nil {
 		for k, name := range strings.Split(findfields, ",") {
 		for k, name := range strings.Split(findfields, ",") {
@@ -1046,7 +1046,7 @@ func GetByNgram(index, itype string, query interface{}, mustquery, findfields, o
 
 
 //增加高亮、过滤查询、高亮截取字数
 //增加高亮、过滤查询、高亮截取字数
 func GetByNgramOther(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool, count int) *[]map[string]interface{} {
 func GetByNgramOther(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool, count int) *[]map[string]interface{} {
-	defer Catch()
+	defer catch()
 	qstr := ""
 	qstr := ""
 	if mustquery != "" && filtermode {
 	if mustquery != "" && filtermode {
 		qstr = GetNgramQuery(query, "", findfields)
 		qstr = GetNgramQuery(query, "", findfields)
@@ -1081,7 +1081,7 @@ func GetByNgramOther(index, itype string, query interface{}, mustquery, findfiel
 //增加高亮、过滤查询
 //增加高亮、过滤查询
 //替换了"号
 //替换了"号
 func GetByNgramAll(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
 func GetByNgramAll(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
-	defer Catch()
+	defer catch()
 	qstr := ""
 	qstr := ""
 	if mustquery != "" && filtermode {
 	if mustquery != "" && filtermode {
 		qstr = GetNgramQuery(query, "", findfields)
 		qstr = GetNgramQuery(query, "", findfields)
@@ -1117,7 +1117,7 @@ func GetByNgramAll(index, itype string, query interface{}, mustquery, findfields
 
 
 //增加高亮、过滤查询
 //增加高亮、过滤查询
 func GetByNgramAll_New(index, itype string, querystring, querymust interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
 func GetByNgramAll_New(index, itype string, querystring, querymust interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
-	defer Catch()
+	defer catch()
 	qstr := ""
 	qstr := ""
 	if filtermode {
 	if filtermode {
 		qstr = GetNgramQuery_New(querystring, querymust, mustquery, findfields)
 		qstr = GetNgramQuery_New(querystring, querymust, mustquery, findfields)

+ 3 - 3
src/qfw/util/elastic/util.go

@@ -8,7 +8,7 @@ import (
 )
 )
 
 
 //obj(string,M)转M,查询用到
 //obj(string,M)转M,查询用到
-func ObjToMap(obj interface{}) *map[string]interface{} {
+func objToMap(obj interface{}) *map[string]interface{} {
 	data := make(map[string]interface{})
 	data := make(map[string]interface{})
 	if s, ok := obj.(string); ok {
 	if s, ok := obj.(string); ok {
 		json.Unmarshal([]byte(strings.Replace(s, "'", "\"", -1)), &data)
 		json.Unmarshal([]byte(strings.Replace(s, "'", "\"", -1)), &data)
@@ -23,7 +23,7 @@ func ObjToMap(obj interface{}) *map[string]interface{} {
 }
 }
 
 
 //对象数组转成string数组
 //对象数组转成string数组
-func ObjArrToStringArr(old []interface{}) []string {
+func objArrToStringArr(old []interface{}) []string {
 	if old != nil {
 	if old != nil {
 		new := make([]string, len(old))
 		new := make([]string, len(old))
 		for i, v := range old {
 		for i, v := range old {
@@ -36,7 +36,7 @@ func ObjArrToStringArr(old []interface{}) []string {
 }
 }
 
 
 //出错拦截
 //出错拦截
-func Catch() {
+func catch() {
 	if r := recover(); r != nil {
 	if r := recover(); r != nil {
 		log.Println(r)
 		log.Println(r)
 		for skip := 0; ; skip++ {
 		for skip := 0; ; skip++ {