wangchuanjin 1 ano atrás
pai
commit
f0ea7b6c15

+ 7 - 3
subrecommend/matcher/ent.go

@@ -75,7 +75,7 @@ func (e *EntMatch) Start() {
 		if subSetUsers[k] != nil && subSetUsers[k].SubSet != nil {
 			ui.SubSet = subSetUsers[k].SubSet
 		}
-		if ui.SubSet == nil && e.AllBehavior[ui.Id].Area != "" {
+		if ui.SubSet == nil && e.AllBehavior[ui.Id] != nil && e.AllBehavior[ui.Id].Area != "" {
 			ui.GetSubSet(false, ui.Id, map[string]interface{}{
 				"o_area": map[string]interface{}{
 					e.AllBehavior[ui.Id].Area: []interface{}{},
@@ -170,7 +170,11 @@ func (e *EntMatch) LoadMySubSet(allSubSet *mr.PayUser, title_pjob, detail_pjob *
 			user.Phone = EntUsers[userId].Phone
 			user.Entniche.Mail = EntUsers[userId].Mail
 		}
-		isChange := ChangeUserObj(temp, subSetType, e.AllBehavior[user.Id].Area)
+		area := ""
+		if e.AllBehavior[user.Id] != nil {
+			area = e.AllBehavior[user.Id].Area
+		}
+		isChange := ChangeUserObj(temp, subSetType, area)
 		subSet, _ := temp["o_entniche"].(map[string]interface{})
 		user.GetSubSet(subSetType == 2, fmt.Sprint(userId), subSet)
 		user.Entniche.IsNew = Ents[entId].IsNew
@@ -259,7 +263,7 @@ func (e *EntMatch) LoadMySubSet(allSubSet *mr.PayUser, title_pjob, detail_pjob *
 								UserId: duk,
 							},
 						}
-						if child_subSet["o_area"] == nil && e.AllBehavior[child_user.Id].Area != "" {
+						if child_subSet["o_area"] == nil && e.AllBehavior[child_user.Id] != nil && e.AllBehavior[child_user.Id].Area != "" {
 							child_subSet["o_area"] = map[string]interface{}{
 								e.AllBehavior[child_user.Id].Area: map[string]interface{}{},
 							}

+ 8 - 2
subrecommend/matcher/person.go

@@ -113,7 +113,10 @@ func (p *PersonMatch) OnceUserBatch(batchIndex int, lastUserId *string) (int, *m
 			users := []*UserInfo{}
 			memberStatus := util.IntAll(temp["i_member_status"])
 			vipStatus := util.IntAll(temp["i_vip_status"])
-			area := p.AllBehavior[userId].Area
+			area := ""
+			if p.AllBehavior[userId] != nil {
+				area = p.AllBehavior[userId].Area
+			}
 			if memberStatus <= 0 && vipStatus <= 0 {
 				isChange := ChangeUserObj(temp, -1, area)
 				ui := NewUserInfo(temp, 1)
@@ -153,7 +156,10 @@ func (p *PersonMatch) OnceUserBatch(batchIndex int, lastUserId *string) (int, *m
 					for _, son := range *MySonAccounts(Mgo, Mgo_User, ui.Id, UserCollFields) {
 						if son_user := NewUserInfo(son, 3); son_user != nil {
 							son_obj, _ := temp["o_member_jy"].(map[string]interface{})
-							son_area := p.AllBehavior[son_user.Id].Area
+							son_area := ""
+							if p.AllBehavior[son_user.Id] != nil {
+								son_area = p.AllBehavior[son_user.Id].Area
+							}
 							if areaIsNil && son_area != "" {
 								if son_obj == nil {
 									son_obj = map[string]interface{}{}

+ 23 - 1
subrecommend/util/util.go

@@ -35,8 +35,28 @@ type Browse struct {
 
 //
 func LoadAllBehavior() map[string]*Behavior {
+	q := `select userid,browse,searchfor from jianyu.sub_recommend_rule`
+	testIds := []string{}
+	if len(Config.TestIds) > 0 {
+		testIds = append(testIds, Config.TestIds...)
+	}
+	if len(Config.TestUserIds) > 0 {
+		for _, v := range Config.TestUserIds {
+			testIds = append(testIds, fmt.Sprint(v))
+		}
+	}
+	if len(testIds) > 0 {
+		q += ` where userid in ('` + strings.Join(testIds, "','") + `')`
+	}
+	logger.Info("开始加载用户行为数据。。", q)
+
+	index := 0
 	allBehavior := map[string]*Behavior{}
 	Clickhouse.SelectByBath(1, func(l *[]map[string]interface{}) bool {
+		index++
+		if index%500 == 0 {
+			logger.Info("加载用户行为数据", index)
+		}
 		searchfor, _ := (*l)[0]["searchfor"].(string)
 		browse, _ := (*l)[0]["browse"].(string)
 		if searchfor == "" && browse == "" {
@@ -65,7 +85,8 @@ func LoadAllBehavior() map[string]*Behavior {
 			Area:       area,
 		}
 		return true
-	}, `select userid,browse,searchfor from jianyu.sub_recommend_rule`)
+	}, q)
+	logger.Info("加载用户行为数据结束。。", index)
 	return allBehavior
 }
 
@@ -216,6 +237,7 @@ func proccessKey(a_key []interface{}) []map[string]interface{} {
 
 //获取相似词
 func GetLikeWord(keys []string) []string {
+	return keys
 	redisKey := fmt.Sprintf("subLikeKey_%s", strings.Join(keys, "+"))
 	b, err := redis.GetNewBytes("pushcache_2_d", redisKey)
 	if err != nil {