|
@@ -40,6 +40,7 @@ type Browse struct {
|
|
|
Infoid string //信息id
|
|
|
Classify string //分类标签,bidding表gov_classify.root,过滤掉只有一级的,取最后一级
|
|
|
Datetime string //访问时间
|
|
|
+ Area string //地区
|
|
|
}
|
|
|
|
|
|
type MatchOther struct {
|
|
@@ -113,7 +114,7 @@ func (m *MatchOther) MatchSearchfor() {
|
|
|
}
|
|
|
lock.Lock()
|
|
|
defer lock.Unlock()
|
|
|
- if cnss := m.CreateNewUserInfo(ui, keys); cnss != nil {
|
|
|
+ if cnss := m.CreateNewUserInfo(ui, "", keys); cnss != nil {
|
|
|
onceUserMap = append(onceUserMap, cnss)
|
|
|
}
|
|
|
}(k)
|
|
@@ -135,6 +136,7 @@ func (m *MatchOther) MatchBrowse(browseCache map[string][]*Browse) {
|
|
|
continue
|
|
|
}
|
|
|
keys := []string{}
|
|
|
+ area := ""
|
|
|
for _, vv := range browseCache[ui.Id] {
|
|
|
datetime, err := time.ParseInLocation(Date_Full_Layout, vv.Datetime, time.Local)
|
|
|
if err != nil {
|
|
@@ -144,9 +146,12 @@ func (m *MatchOther) MatchBrowse(browseCache map[string][]*Browse) {
|
|
|
if datetime.Before(time.Now().AddDate(0, 0, -Config.BrowseLimitDay)) {
|
|
|
continue
|
|
|
}
|
|
|
+ if len(keys) == 0 {
|
|
|
+ area = vv.Area
|
|
|
+ }
|
|
|
keys = append(keys, vv.Classify)
|
|
|
}
|
|
|
- if cnss := m.CreateNewUserInfo(ui, keys); cnss != nil {
|
|
|
+ if cnss := m.CreateNewUserInfo(ui, area, keys); cnss != nil {
|
|
|
onceUserMap = append(onceUserMap, cnss)
|
|
|
}
|
|
|
}
|
|
@@ -156,7 +161,7 @@ func (m *MatchOther) MatchBrowse(browseCache map[string][]*Browse) {
|
|
|
}
|
|
|
|
|
|
//
|
|
|
-func (m *MatchOther) CreateNewUserInfo(ui *UserInfo, keys []string) *UserInfo {
|
|
|
+func (m *MatchOther) CreateNewUserInfo(ui *UserInfo, area string, keys []string) *UserInfo {
|
|
|
if len(keys) == 0 {
|
|
|
return nil
|
|
|
}
|
|
@@ -167,6 +172,11 @@ func (m *MatchOther) CreateNewUserInfo(ui *UserInfo, keys []string) *UserInfo {
|
|
|
Keys: keys,
|
|
|
OriginalKeys: keys,
|
|
|
},
|
|
|
+ Extend: &UserInfoExtend{
|
|
|
+ Object: map[string]interface{}{
|
|
|
+ "area": area,
|
|
|
+ },
|
|
|
+ },
|
|
|
}
|
|
|
if ui.SubSet != nil {
|
|
|
userInfo.SubSet.Area = ui.SubSet.Area
|
|
@@ -242,10 +252,15 @@ func (m *MatchOther) MergeInfos(userMap *map[*UserInfo]*SortList) {
|
|
|
}
|
|
|
|
|
|
//
|
|
|
-func Save(userId, area string, infos *SortList, maxSize int) {
|
|
|
+func Save(ui *UserInfo, infos *SortList) {
|
|
|
// for _, vv := range *infos {
|
|
|
// logger.Info(userId, "-----", vv.Info["title"], vv.Keys)
|
|
|
// }
|
|
|
+ area := ""
|
|
|
+ if ui.Extend != nil && ui.Extend.Object != nil {
|
|
|
+ area, _ = ui.Extend.Object["area"].(string)
|
|
|
+ }
|
|
|
+ maxSize := getMaxSize(ui)
|
|
|
subCount, searchforCount, browseCount := 0, 0, 0
|
|
|
sort.Sort(infos)
|
|
|
matchLen := len(*infos)
|
|
@@ -264,18 +279,18 @@ func Save(userId, area string, infos *SortList, maxSize int) {
|
|
|
subCount++
|
|
|
}
|
|
|
}
|
|
|
- logger.Info(userId, "匹配上", matchLen, "条", "保存", len(*infos), "条", "订阅", subCount, "搜索", searchforCount, "浏览", browseCount)
|
|
|
+ logger.Info(ui.Id, "匹配上", matchLen, "条", "保存", len(*infos), "条", "订阅", subCount, "搜索", searchforCount, "浏览", browseCount)
|
|
|
if len(ids) == 0 {
|
|
|
return
|
|
|
}
|
|
|
nowFormat := NowFormat(Date_Full_Layout)
|
|
|
- datas := Clickhouse.SelectBySql(`select bitmapToArray(infoids) as infoids from jianyu.sub_recommend_list where userid=? order by update_time desc limit 1`, userId)
|
|
|
+ datas := Clickhouse.SelectBySql(`select bitmapToArray(infoids) as infoids from jianyu.sub_recommend_list where userid=? order by update_time desc limit 1`, ui.Id)
|
|
|
if datas == nil {
|
|
|
- logger.Error(userId, "查询clickhouse失败")
|
|
|
+ logger.Error(ui.Id, "查询clickhouse失败")
|
|
|
return
|
|
|
}
|
|
|
if len(*datas) == 0 {
|
|
|
- Clickhouse.InsertBySql(`INSERT INTO jianyu.sub_recommend_list (userid, infoids, area, update_time) values ('` + userId + `',bitmapBuild([` + toUInt64(ids) + `]),'` + area + `','` + nowFormat + `')`)
|
|
|
+ Clickhouse.InsertBySql(`INSERT INTO jianyu.sub_recommend_list (userid, infoids, area, update_time) values ('` + ui.Id + `',bitmapBuild([` + toUInt64(ids) + `]),'` + area + `','` + nowFormat + `')`)
|
|
|
} else {
|
|
|
infoids, _ := (*datas)[0]["infoids"].([]uint64)
|
|
|
intIds := []int{}
|
|
@@ -293,7 +308,7 @@ func Save(userId, area string, infos *SortList, maxSize int) {
|
|
|
if len(intIds) > maxSize {
|
|
|
intIds = intIds[len(intIds)-maxSize:]
|
|
|
}
|
|
|
- text := `ALTER TABLE jianyu.sub_recommend_list update area='` + area + `',infoids=bitmapBuild([` + toUInt64(intIds) + `]),update_time='` + nowFormat + `' where userid='` + userId + `'`
|
|
|
+ text := `ALTER TABLE jianyu.sub_recommend_list update area='` + area + `',infoids=bitmapBuild([` + toUInt64(intIds) + `]),update_time='` + nowFormat + `' where userid='` + ui.Id + `'`
|
|
|
Clickhouse.UpdateOrDeleteBySql(text)
|
|
|
}
|
|
|
}
|