From 9969f8072b23fd8d03cb38445a81ae881bd01ee2 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期三, 25 九月 2019 17:37:09 +0800
Subject: [PATCH] optimization get personId function

---
 EsClient.go |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/EsClient.go b/EsClient.go
index 5a8d88b..3f5740e 100644
--- a/EsClient.go
+++ b/EsClient.go
@@ -16,7 +16,7 @@
 func Parsesources(sources []map[string]interface{}) (esinfos []*protomsg.Esinfo) {
     var ok bool
     for _, source := range sources {
-       var tmpinfo protomsg.Esinfo
+        tmpinfo := protomsg.Esinfo{}
         tmpinfo.FaceFeature, ok =   source["faceFeature"].(string)
         if !ok {
             continue
@@ -58,8 +58,9 @@
 func Videopersonsbyid(sources []map[string]interface{}) (tmpinfos []protomsg.Videopersons) {
     var ok bool
 
-    var tmpinfo protomsg.Videopersons
+    //var tmpinfo protomsg.Videopersons
     for _, source := range  sources{
+        tmpinfo := protomsg.Videopersons{}
         tmpinfo.Id, ok =   source["id"].(string)
         if !ok {
             continue
@@ -211,8 +212,9 @@
 func Dbpersonbyid(sources []map[string]interface{}) (tmpinfos []protomsg.Dbperson) {
         var ok bool
 
-        var tmpinfo protomsg.Dbperson
+        //var tmpinfo protomsg.Dbperson
         for _, source := range  sources{
+            tmpinfo := protomsg.Dbperson{}
             tmpinfo.FaceFeature, ok =   source["faceFeature"].(string)
             if !ok {
                 continue
@@ -279,9 +281,9 @@
 func Dbtablebyid(sources []map[string]interface{}) (tmpinfos []protomsg.Dbtable) {
     var ok bool
 
-    var tmpinfo protomsg.Dbtable
+    //var tmpinfo protomsg.Dbtable
     for _, source := range  sources{
-
+        tmpinfo := protomsg.Dbtable{}
         tmpinfo.Id, ok    =   source["id"].(string)
         if !ok {
             continue
@@ -357,6 +359,45 @@
     }
     return sources,nil
 }
+//slice scroll 瑙f瀽宸ュ叿鍑芥暟
+func Sourcelistforscroll(buf []byte)(datasource map[string]interface{}, err error){
+	var data = make(map[string]interface{})
+	var info interface{}
+	json.Unmarshal(buf, &info)
+	out, ok := info.(map[string]interface{})
+	if !ok {
+		return nil, errors.New("http response interface can not change map[string]interface{}")
+	}
+	scroll_id, ok := out["_scroll_id"].(string)
+	if !ok {
+		return nil, errors.New("first hits change error!")
+	}
+
+	//fmt.Println("middle: ",scroll_id)
+	middle, ok := out["hits"].(map[string]interface{})
+	//fmt.Println("middle: ",out)
+	if !ok {
+		return nil, errors.New("first hits change error!")
+	}
+	var sources  = make([]map[string]interface{},0)
+	for _, in := range middle["hits"].([]interface{}){
+		tmpbuf, ok := in.(map[string]interface{})
+		if !ok {
+			fmt.Println("change to source error!")
+			continue
+		}
+		source, ok := tmpbuf["_source"].(map[string]interface{})
+		if !ok {
+			fmt.Println("change _source error!")
+			continue
+		}
+		sources  = append(sources, source )
+	}
+
+	data["sourcelist"] = sources
+	data["scroll_id"] = scroll_id
+	return data,nil
+}
 
 func EsReq(method string, url string, parama []byte) (buf []byte, err error) {
     defer elapsed("page")()

--
Gitblit v1.8.0