Browse Source

用户行业分类 - 完善字段信息

wcc 2 năm trước cách đây
mục cha
commit
2819b57128
1 tập tin đã thay đổi với 24 bổ sung15 xóa
  1. 24 15
      src/task/task.go

+ 24 - 15
src/task/task.go

@@ -590,7 +590,6 @@ func DealUserKey(tt *TTask) {
 	extractquery := sess.DB(tt.S_mgodb).C(tt.S_coll).Find(q).Select(nil).Sort("_id").Iter()
 
 	sum := 0
-	realCount := 0
 	for tmp := make(map[string]interface{}); extractquery.Next(&tmp); sum++ {
 		lastID = u.BsonIdToSId(tmp["_id"])
 
@@ -614,30 +613,37 @@ func DealUserKey(tt *TTask) {
 			if len(keys) > 0 {
 				//用户关键词
 				update["key_list"] = strings.Join(tags, ",")
+				update["i_appid"] = tmp["i_appid"]
 				update["_id"] = tmp["_id"]
 			}
 
 			lock.Lock()
-			tmp["key_list"] = strings.Join(tags, ",")
 			SMap := NewClassificationRun(tt, tmp)
-			//fmt.Println("SMap=>", SMap)
 			subtype := SMap.Map["subscope_dy"]
-
-			if tt.S_table != "" {
-				// 存储到结果表
-				if subtype != nil {
-					if subs, ok := subtype.([]string); ok {
-						update["subscope_dy"] = strings.Join(subs, ",")
+			// 存储到结果表
+			if subtype != nil {
+				if subs, ok := subtype.([]string); ok {
+					tops := []string{}
+					for _, v := range subs {
+						top := strings.Split(v, "_")[0]
+						tops = append(tops, top)
 					}
-					saveUserPool = append(saveUserPool, update)
-					realCount++
+					update["subscope_dy"] = strings.Join(subs, ",")
+					update["topscope_dy"] = strings.Join(tops, ",")
 				}
-				if len(saveUserPool) > NN {
+			}
+
+			if len(update) > 0 {
+				saveUserPool = append(saveUserPool, update)
+			}
+
+			if len(saveUserPool) > NN {
+				//存储到新表
+				if tt.S_table != "" {
 					tt.MgoTask.SaveBulk(tt.S_table, saveUserPool...)
 					saveUserPool = []map[string]interface{}{}
 				}
 			}
-
 			lock.Unlock()
 
 		}(tmp)
@@ -648,8 +654,11 @@ func DealUserKey(tt *TTask) {
 	wg.Wait()
 
 	if len(saveUserPool) > 0 {
-		tt.MgoTask.SaveBulk(tt.S_table, saveUserPool...)
-		saveUserPool = []map[string]interface{}{}
+		//存储到新表
+		if tt.S_table != "" {
+			tt.MgoTask.SaveBulk(tt.S_table, saveUserPool...)
+			saveUserPool = []map[string]interface{}{}
+		}
 	}
 
 	if lastID > tt.LastId {