|
@@ -31,8 +31,96 @@ var (
|
|
|
HtmlReg = regexp.MustCompile("<[^>]+>")
|
|
|
)
|
|
|
|
|
|
+// biddingDetailTask 针对 detail contenthtml 二个字段的索引;bidding_detail
|
|
|
+func biddingDetailTask(mapInfo map[string]interface{}) {
|
|
|
+ defer util.Catch()
|
|
|
+
|
|
|
+ //stype := util.ObjToString(mapInfo["stype"])
|
|
|
+ q, _ := mapInfo["query"].(map[string]interface{})
|
|
|
+ if q == nil {
|
|
|
+ q = map[string]interface{}{
|
|
|
+ "_id": map[string]interface{}{
|
|
|
+ "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
|
|
|
+ "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //针对gte/lte,单独转换
|
|
|
+ q = convertToMongoID(q)
|
|
|
+ }
|
|
|
+
|
|
|
+ ch := make(chan bool, 10)
|
|
|
+ wg := &sync.WaitGroup{}
|
|
|
+
|
|
|
+ //bidding库
|
|
|
+ biddingConn := MgoB.GetMgoConn()
|
|
|
+ count, _ := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(&q).Count()
|
|
|
+ log.Info("biddingDetailTask", zap.Int64("同步总数:", count))
|
|
|
+ it := biddingConn.DB(config.Conf.DB.MongoB.Dbname).C(config.Conf.DB.MongoB.Coll).Find(&q).Select(nil).Iter()
|
|
|
+ c1, index := 0, 0
|
|
|
+ var indexLock sync.Mutex
|
|
|
+ for tmp := make(map[string]interface{}); it.Next(tmp); c1++ {
|
|
|
+ if c1%1000 == 0 {
|
|
|
+ log.Info("biddingDetailTask", zap.Int("current:", c1))
|
|
|
+ log.Info("biddingDetailTask", zap.Any("current:_id =>", tmp["_id"]))
|
|
|
+ }
|
|
|
+ ch <- true
|
|
|
+ wg.Add(1)
|
|
|
+ // 创建一个新的map用于goroutine,避免重用
|
|
|
+ docCopy := make(map[string]interface{})
|
|
|
+ for k, v := range tmp {
|
|
|
+ docCopy[k] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ go func(tmp map[string]interface{}) {
|
|
|
+ defer func() {
|
|
|
+ <-ch
|
|
|
+ wg.Done()
|
|
|
+ }()
|
|
|
+
|
|
|
+ indexLock.Lock()
|
|
|
+ index++
|
|
|
+ indexLock.Unlock()
|
|
|
+
|
|
|
+ //
|
|
|
+ detail, _ := tmp["detail"].(string)
|
|
|
+ detail = filterSpace.ReplaceAllString(detail, "")
|
|
|
+ detail_new := ""
|
|
|
+
|
|
|
+ if tmp["cleartag"] != nil {
|
|
|
+ if tmp["cleartag"].(bool) {
|
|
|
+ text, _ := FilterDetail(detail)
|
|
|
+ detail_new = util.ObjToString(tmp["title"]) + " " + text
|
|
|
+ } else {
|
|
|
+ detail_new = util.ObjToString(tmp["title"]) + " " + detail
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ text, _ := FilterDetail(detail)
|
|
|
+ detail_new = util.ObjToString(tmp["title"]) + " " + text
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ insert := map[string]interface{}{
|
|
|
+ "detail": detail_new,
|
|
|
+ "id": mongodb.BsonIdToSId(tmp["_id"]),
|
|
|
+ "_id": mongodb.BsonIdToSId(tmp["_id"]),
|
|
|
+ "contenthtml": tmp["contenthtml"],
|
|
|
+ }
|
|
|
+ //
|
|
|
+ saveDetailEsPool <- insert
|
|
|
+
|
|
|
+ }(docCopy)
|
|
|
+ tmp = map[string]interface{}{}
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ log.Info("biddingDetailTask over", zap.Int("count", c1), zap.Int("index", index))
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
func biddingTask(mapInfo map[string]interface{}) {
|
|
|
defer util.Catch()
|
|
|
+ // 同时处理详情索引
|
|
|
+ go biddingDetailTask(mapInfo)
|
|
|
|
|
|
stype := util.ObjToString(mapInfo["stype"])
|
|
|
q, _ := mapInfo["query"].(map[string]interface{})
|
|
@@ -137,6 +225,7 @@ func biddingTask(mapInfo map[string]interface{}) {
|
|
|
//之前存在pici,就不在添加
|
|
|
if pici, ok := tmp["pici"]; ok {
|
|
|
newTmp["pici"] = pici
|
|
|
+ //log.Info("dddddddd", zap.Any("bidding_id", tmp["_id"]), zap.Any("pici", pici))
|
|
|
} else {
|
|
|
newTmp["pici"] = time.Now().Unix()
|
|
|
update["pici"] = time.Now().Unix()
|
|
@@ -640,11 +729,11 @@ func GetEsField(tmp map[string]interface{}, stype string) (map[string]interface{
|
|
|
}
|
|
|
}
|
|
|
YuceEndtime(newTmp) // 预测结果时间
|
|
|
- if stype == "bidding" || stype == "bidding_history" || stype == "index-by-id" {
|
|
|
- newTmp["createtime"] = time.Now().Unix() // es库数据创建时间,只有增量数据有
|
|
|
- newTmp["pici"] = time.Now().Unix() //createtime跟pici一样,为了剑鱼功能需要,并行存在一段时间,之后可以删掉createtime
|
|
|
- update["pici"] = time.Now().Unix()
|
|
|
- }
|
|
|
+ //if stype == "bidding" || stype == "bidding_history" || stype == "index-by-id" {
|
|
|
+ // newTmp["createtime"] = time.Now().Unix() // es库数据创建时间,只有增量数据有
|
|
|
+ // newTmp["pici"] = time.Now().Unix() //createtime跟pici一样,为了剑鱼功能需要,并行存在一段时间,之后可以删掉createtime
|
|
|
+ // update["pici"] = time.Now().Unix()
|
|
|
+ //}
|
|
|
|
|
|
if len(saveErr) > 0 {
|
|
|
saveErr["infoid"] = mongodb.BsonIdToSId(tmp["_id"])
|