biddingindexback.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "go.mongodb.org/mongo-driver/bson"
  4. util "utils"
  5. "utils/mongodb"
  6. )
  7. func (t *TaskInfo) biddingBackTask(data []byte, mapInfo map[string]interface{}) {
  8. defer util.Catch()
  9. q, _ := mapInfo["query"].(map[string]interface{})
  10. if q == nil {
  11. q = map[string]interface{}{
  12. "_id": bson.M{
  13. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  14. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  15. },
  16. }
  17. }
  18. //bidding库
  19. biddingConn := biddingMgo.GetMgoConn()
  20. defer biddingMgo.DestoryMongoConn(biddingConn)
  21. c := util.ObjToString(mapInfo["coll"])
  22. if c == "" {
  23. c = bidding["collect"].(string)
  24. } else {
  25. currentColl = c
  26. }
  27. count, _ := biddingConn.DB(biddingMgo.DbName).C(c).Find(&q).Count()
  28. util.Debug("查询语句:", q, "同步总数:", count)
  29. //查询招标数据
  30. query := biddingConn.DB(biddingMgo.DbName).C(c).Find(q).Select(bson.M{
  31. "projectinfo.attachment": 0,
  32. "contenthtml": 0,
  33. "publishdept": 0,
  34. }).Sort("_id").Iter()
  35. //查询抽取结果
  36. n := 0
  37. var mpool = make(chan bool, t.thread)
  38. for tmp := make(map[string]interface{}); query.Next(tmp); n++ {
  39. if n%20000 == 0 {
  40. util.Debug("current:", n, tmp["_id"])
  41. }
  42. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  43. tmp = make(map[string]interface{})
  44. continue
  45. }
  46. if util.IntAll(tmp["extracttype"]) == -1 {
  47. tmp = make(map[string]interface{})
  48. continue
  49. }
  50. mpool <- true
  51. go func(tmp map[string]interface{}) {
  52. defer func() {
  53. <-mpool
  54. }()
  55. newTmp := GetEsField(tmp, nil, t.stype)
  56. saveEsElsePool <- newTmp
  57. }(tmp)
  58. tmp = make(map[string]interface{})
  59. }
  60. util.Debug(mapInfo, "create biddingback index...over", n)
  61. }