Kaynağa Gözat

添加 中国移动定制标签 mobile_tag

wcc 1 yıl önce
ebeveyn
işleme
e24f65e591
4 değiştirilmiş dosya ile 174 ekleme ve 21 silme
  1. 12 9
      createEsIndex/bidding_es.go
  2. 8 2
      createEsIndex/init.go
  3. 6 10
      createEsIndex/main.go
  4. 148 0
      createEsIndex/utils.go

+ 12 - 9
createEsIndex/bidding_es.go

@@ -127,6 +127,18 @@ func biddingTask(mapInfo map[string]interface{}) {
 				newTmp["pici"] = time.Now().Unix()
 				update["pici"] = time.Now().Unix()
 			}
+			//todo 处理中国移动定制标签
+			if len(globalRegs) > 0 && len(MatchArr) > 0 {
+				gs, _, _ := TaskTags(tmp, globalRegs)
+				if len(gs) > 0 {
+					tags, match, add := TaskTags(tmp, MatchArr)
+					if len(tags) > 0 {
+						newTmp["mobile_tag"] = tags
+						update["mobile_tag"] = tags
+						log.Info("biddingTask", zap.Any(mongodb.BsonIdToSId(tmp["_id"]), match+","+add))
+					}
+				}
+			}
 			//
 			saveEsPool <- newTmp
 			if len(update) > 0 {
@@ -224,15 +236,6 @@ func biddingAllTask(mapInfo map[string]interface{}) {
 				<-ch
 				wg.Done()
 			}()
-			////判断是否是预处理数据;pre_id 是标识
-			//if config.Conf.Env.OpenPre {
-			//	if pre_id, ok := tmp["pre_id"]; ok {
-			//		preID := util.ObjToString(pre_id)
-			//		if preID != "" {
-			//			deletePreEsData(preID)
-			//		}
-			//	}
-			//}
 
 			if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
 				tmp = make(map[string]interface{})

Dosya farkı çok büyük olduğundan ihmal edildi
+ 8 - 2
createEsIndex/init.go


+ 6 - 10
createEsIndex/main.go

@@ -69,17 +69,13 @@ func init() {
 	InitMysql()
 	InitMgo()
 	InitEs()
-	InitField()
-	InitBitmap()
+	InitField()  //初始化项目数据升索引字段
+	InitBitmap() //初始化项目名称副标题 bitmap
+	InitRule()   //初始化中国移动定制标签规则
 
-	//if config.Conf.Env.OpenPre {
-	//	InitPreProcessField()
-	//	InitPreEsClient()
-	//}
-
-	InitEsBiddingField()
-	oss.InitOss()
-	verifyESFields() //检测es 字段类型
+	InitEsBiddingField() //初始bidding数据升索引字段
+	oss.InitOss()        // 初始化oss 存储
+	verifyESFields()     //检测es 字段类型
 
 	JyUdpAddr = &net.UDPAddr{
 		IP:   net.ParseIP(config.Conf.Udp.JyAddr),

+ 148 - 0
createEsIndex/utils.go

@@ -730,3 +730,151 @@ func GetPackages(title string) (res []string) {
 	}
 	return res
 }
+
+// TagMatching 标签结构体
+type TagMatching struct {
+	tagName       string        //标签名称
+	tagCode       string        //标签值(保存)
+	matchField    []string      //关键词匹配字段,title,detail
+	matchKey      string        //匹配的词语,多个使用逗号连接,"部队,国防,军事,军用"
+	matchKeyReg   []*RegexpInfo //关键词的正则
+	addField      []string      //附加词匹配字段
+	addKey        string        //附件词匹配关键词
+	addKeyReg     []*RegexpInfo //附加次的正则
+	excludeField  []string      //排除词匹配字段
+	excludeKey    string        //排除词匹配词
+	excludeKeyReg []*RegexpInfo //排除词正则
+	//clearKey      []string      //清理词匹配字段跟关键词一样
+}
+
+// RegexpInfo 关键词正则
+type RegexpInfo struct {
+	keyStr string
+	regs   *regexp.Regexp
+}
+
+// GetRegex 根据关键词或者对应正则
+func GetRegex(key string) []*RegexpInfo {
+	var infos []*RegexpInfo
+	for _, s := range strings.Split(key, ",") {
+		if strings.Contains(s, "&&") || strings.Contains(s, "&!") {
+			info := &RegexpInfo{
+				keyStr: s,
+				regs:   nil,
+			}
+			infos = append(infos, info)
+		} else {
+			info := &RegexpInfo{
+				keyStr: s,
+				regs:   regexp.MustCompile(".*(?i)" + s + ".*"),
+			}
+			infos = append(infos, info)
+		}
+
+	}
+	return infos
+}
+
+// TaskTags 根据数据和正则规则,验证数据标签
+func TaskTags(tmp map[string]interface{}, regs []TagMatching) (tags []string, keyWord, addWord string) {
+	// 在匹配字段里,比如标题满足了关键词,详情满足附加词,关键词的匹配字段含有标题,附加词的匹配字段含有详情;就符合条件
+Loop:
+	for _, v := range regs {
+		keyR := false // 关键词匹配结果
+		addR := false //附加次匹配结果
+		// 1.排除词
+		if len(v.excludeField) > 0 && len(v.excludeKeyReg) > 0 {
+			// 遍历排除词对应的tmp字段信息
+			for _, f := range v.excludeField {
+				if val := util.ObjToString(tmp[f]); val != "" {
+					if rs, _ := getRegsResult(val, v.excludeKeyReg); rs {
+						//有排除词,直接判断下一个规则
+						continue Loop
+					}
+				}
+			}
+		}
+
+		// 清理词;目的把 类似 fuck的单词替换为空字符串
+		//if len(v.clearKey) > 0 && len(v.matchField) > 0 {
+		//	for _, s := range v.clearKey {
+		//		for _, f := range v.matchField {
+		//			if val := util.ObjToString(tmp[f]); val != "" {
+		//				tmp[f] = strings.ReplaceAll(val, s, "")
+		//			}
+		//		}
+		//	}
+		//}
+
+		// 关键词
+		if len(v.matchField) > 0 && len(v.matchKeyReg) > 0 {
+			for _, f := range v.matchField {
+				if val := util.ObjToString(tmp[f]); val != "" {
+					if rs, da := getRegsResult(val, v.matchKeyReg); rs {
+						keyR = true
+						keyWord = da
+						//log.Print("key", da)
+						break
+					}
+				}
+			}
+		}
+
+		// 附加词
+		if len(v.addField) > 0 && len(v.addKeyReg) > 0 && keyR {
+			for _, f := range v.addField {
+				if val := util.ObjToString(tmp[f]); val != "" {
+					if rs, da := getRegsResult(val, v.addKeyReg); rs {
+						addR = true
+						addWord = da
+						//log.Println("add", da)
+						break
+					}
+				}
+			}
+		} else {
+			addR = true
+		}
+
+		// 满足 关键词和附加词条件
+		if keyR && addR {
+			// 去重相同标签
+			if !IsInStringArray(v.tagName, tags) {
+				tags = append(tags, v.tagName)
+			}
+		}
+	}
+
+	return
+}
+
+// getRegsResult 验证数据是否符合数组正则
+func getRegsResult(data string, regs []*RegexpInfo) (res bool, a string) {
+	for _, e1 := range regs {
+		if e1.regs != nil && e1.regs.MatchString(data) {
+			return true, e1.regs.String()
+		} else {
+			// && 特殊处理
+			if strings.Contains(e1.keyStr, "&&") {
+				flag := true
+				for _, s := range strings.Split(e1.keyStr, "&&") {
+					if !strings.Contains(data, s) {
+						flag = false
+						break
+					}
+				}
+				if flag {
+					return true, e1.keyStr
+				}
+			}
+			// 前面是必须有的关键词&!,后面是不能有的关键词;比如 军队&!点军队,
+			if strings.Contains(e1.keyStr, "&!") {
+				keys := strings.Split(e1.keyStr, "&!")
+				if strings.Contains(data, keys[0]) && !strings.Contains(data, keys[1]) {
+					return true, e1.keyStr
+				}
+			}
+		}
+	}
+	return false, ""
+}

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor