123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package matcher
- import (
- . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
- )
- //免费用户
- type FreeUser struct {
- Users map[*UserInfo]bool
- Title_KeyDfa *KeyDfa
- AreaUsers map[string]map[*UserInfo]bool
- SubtypeUsers map[string]map[*UserInfo]bool
- }
- //
- func NewFreeUser() *FreeUser {
- return &FreeUser{
- Users: map[*UserInfo]bool{},
- AreaUsers: map[string]map[*UserInfo]bool{},
- SubtypeUsers: map[string]map[*UserInfo]bool{},
- }
- }
- //
- func (f *FreeUser) Match(poolSize int, datas *[]map[string]interface{}) (*map[*UserInfo]*SortList, *map[*UserInfo]*[]string) {
- return EachFoMatch(f, poolSize, datas)
- }
- //
- func (f *FreeUser) ToMatch(info map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) {
- area, _ := info["area"].(string)
- if area == "全国" {
- area = ""
- }
- toptype, _ := info["toptype"].(string)
- title := GetInfoTitle(info)
- //订阅词
- keys := f.Title_KeyDfa.Key.Analy(title)
- //排除词
- notkeys := f.Title_KeyDfa.NotKey.Analy(title)
- title_users := f.GetFinalUser(keys, notkeys, f.Title_KeyDfa.Key_user, info)
- users := map[*UserInfo]*MatchUser{}
- for k, _ := range f.Users {
- if k.SubSet.IsUpgrade && ((!f.AreaUsers[""][k] && !f.AreaUsers[area][k]) || (!f.SubtypeUsers[""][k] && !f.SubtypeUsers[toptype][k])) {
- continue
- }
- var matchUser *MatchUser
- if len(k.SubSet.Keys) > 0 {
- matchUser = (*title_users)[k]
- if matchUser == nil {
- continue
- }
- } else {
- matchUser = &MatchUser{}
- }
- users[k] = matchUser
- }
- return &users, nil
- }
- //获取最终的用户,排除词、信息范围、信息类型之后的
- //返回匹配上的用户和没有匹配到的用户
- func (f *FreeUser) GetFinalUser(keys, notkeys []string, keyUser *map[string]*[]*UserInfo, info map[string]interface{}) *map[*UserInfo]*MatchUser {
- area, _ := info["area"].(string)
- toptype, _ := info["toptype"].(string)
- keyMap := map[string]bool{}
- for _, v := range keys {
- keyMap[v] = true
- }
- users := map[*UserInfo]*MatchUser{} //匹配到用户
- //遍历所有用户
- for k, us := range *keyUser {
- if !keyMap[k] { //该关键词没有匹配到的用户
- continue
- }
- for _, u := range *us {
- //获取该词下面所有的用户
- //遍历我的排除词,如果存在的话,排除自己
- isContinue := false
- for _, notkey := range notkeys {
- if u.SubSet.Key_notkey[k][notkey] {
- isContinue = true
- break
- }
- }
- if isContinue {
- continue
- }
- if !u.SubSet.IsUpgrade {
- //遍历我的信息范围,看该信息是不是在我的信息范围中
- if len(u.SubSet.Key_area[k]) > 0 && !u.SubSet.Key_area[k][area] {
- continue
- }
- //遍历我的信息类型,看该信息是不是在我的信息类型中
- if len(u.SubSet.Key_subtype[k]) > 0 && !u.SubSet.Key_subtype[k][toptype] {
- continue
- }
- }
- matchUser := users[u]
- if matchUser == nil {
- matchUser = &MatchUser{
- Keys: []string{},
- }
- }
- matchUser.Keys = append(matchUser.Keys, k)
- users[u] = matchUser
- }
- }
- return &users
- }
|