From a298411166eb97edcce21ae42b1aeb763af8a8f0 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期三, 17 七月 2019 18:28:19 +0800
Subject: [PATCH] Refactoring face alignment and caching

---
 esutil/EsApi.go |   51 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/esutil/EsApi.go b/esutil/EsApi.go
index 7e7cbf1..17de9aa 100644
--- a/esutil/EsApi.go
+++ b/esutil/EsApi.go
@@ -10,12 +10,33 @@
         )
 
 // 鏌ヨ搴曞簱浜哄憳淇℃伅
-func DbPersoninfos( queryindex int, querynums int ) ([]*protomsg.Esinfo, error){
+func Personinfos( queryIndex int, queryNums int, indexName string, serverIp string, serverPort string, analyServerId string) ([]*protomsg.Esinfo, error){
             var dbinfos []*protomsg.Esinfo
-            point   := strconv.Itoa(queryindex)
-            number   := strconv.Itoa(querynums)
-
-            var dbinfoRequest =  `  {
+            point   := strconv.Itoa(queryIndex)
+            number   := strconv.Itoa(queryNums)
+            JsonDSL  := ""
+            if indexName == "videopersons" {
+                 JsonDSL =  `  {
+                    "from": ` + point +  `, 
+                    "query": {
+                        "bool": {
+                            "filter": [
+                                {
+                                    "term": {
+                                        "analyServerId": ` + analyServerId + `
+                                    }
+                                }
+                            ]
+                        }
+                    },
+                    "size":`+ number +`,
+                    "_source": [
+                        "id",
+                        "faceFeature"
+                    ]
+                }`
+            }else {
+                 JsonDSL =  `  {
                     "from": ` + point +  `,        
                     "query": {
                         "match_all": {}
@@ -27,8 +48,8 @@
                        "faceFeature"
                        ]
                     }`
-
-    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtablepersons/dbpersons/_search",[]byte(dbinfoRequest))
+            }
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(JsonDSL))
     if err != nil {
         return dbinfos ,errors.New("http request dbtablename info is err!")
     }
@@ -45,7 +66,7 @@
 }
 
 // 鏍规嵁搴曞簱id鏌ヨ搴曞簱淇℃伅
-func Dbtablefosbyid (id []string) ([]protomsg.Dbtable, error) {
+func Dbtablefosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.Dbtable, error) {
     var dbinfo []protomsg.Dbtable
     dbtableId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
         var dbinfoRequest = `
@@ -54,7 +75,7 @@
             		"bool": {
             			"filter": [{
             				"terms": {
-            					"_id": [
+            					"id": [
             						"`+ dbtableId +`"
             					]
             				}
@@ -63,7 +84,7 @@
             	}
             }
         `
-    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtables/_search",[]byte(dbinfoRequest))
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfoRequest))
     if err != nil {
         return dbinfo,  err
     }
@@ -78,7 +99,7 @@
 }
 
 // 鏍规嵁搴曞簱浜哄憳id鏌ヨ搴曞簱浜哄憳淇℃伅
-func Dbpersoninfosbyid (id []string) ([]protomsg.Dbperson, error) {
+func Dbpersoninfosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.Dbperson, error) {
     var dbinfo []protomsg.Dbperson
     dbtablePersonId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
     var dbinfoRequest = `
@@ -87,7 +108,7 @@
             		"bool": {
             			"filter": [{
             				"terms": {
-            					"_id": [
+            					"id": [
             						"`+ dbtablePersonId +`"
             					]
             				}
@@ -96,7 +117,7 @@
             	}
             }
         `
-    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtablepersons/_search",[]byte(dbinfoRequest))
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfoRequest))
     if err != nil {
         return dbinfo,  err
     }
@@ -112,7 +133,7 @@
 }
 
 // 鏍规嵁tableid 鏌ヨtablename
-func Dbtablename(tableid string ) (tablename string, err error) {
+func Dbtablename(tableid string, indexName string, serverIp string, serverPort string) (tablename string, err error) {
     var dbinfotable =` {
         "query": {
             "bool": {
@@ -130,7 +151,7 @@
         ]
     }
     `
-    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtables/_search",[]byte(dbinfotable))
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfotable))
     if err != nil {
         return "" ,errors.New("http request dbtablename info is err!")
     }

--
Gitblit v1.8.0