search.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. package util
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. ME "app.yhyue.com/moapp/jybase/encrypt"
  5. elastic "app.yhyue.com/moapp/jybase/esv1"
  6. "crypto/rand"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. "io/ioutil"
  11. IC "jyBXCore/rpc/init"
  12. "jyBXCore/rpc/type/bxcore"
  13. "log"
  14. "math/big"
  15. "net/http"
  16. "net/url"
  17. "regexp"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "unicode"
  22. )
  23. var ClearHtml = regexp.MustCompile("<[^>]*>")
  24. var MatchSpace = regexp.MustCompile("\\s+")
  25. var filterReg_3 = regexp.MustCompile("(项目|公告|公示)$")
  26. var filterReg_2 = regexp.MustCompile("^[)\\)>》】\\]}}〕,,;;::'\"“”。.\\??、/+=\\_—*&……\\^%$¥@!!`~·(\\(<《【\\[{{〔]+$")
  27. var filterReg_1 = regexp.MustCompile("^([0-9]{1,3}|[零一二三四五六七八九十]{1,2}|联系人?|电话|地址|编号|采购|政府采购|成交|更正|招标|中标|变更|结果)$")
  28. var filterReg = regexp.MustCompile("^[的人号时元万公告项目地址电话邮编日期联系招标中结果成交项目项目采购采购项目政府采购公告更正公告]+$")
  29. var PhoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
  30. var EmailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
  31. func SearchHistory(history, searchvalue string) (arrs []string) {
  32. if searchvalue != "" {
  33. arrs = strings.Split(history, ",")
  34. //新增历史记录
  35. if history == "" {
  36. arrs = make([]string, 0)
  37. }
  38. for k, v := range arrs {
  39. if v == strings.TrimSpace(searchvalue) {
  40. arrs = append(arrs[:k], arrs[k+1:]...)
  41. break
  42. }
  43. }
  44. arrs = append(arrs, searchvalue)
  45. if len(arrs) > 10 {
  46. arrs = arrs[1:11]
  47. }
  48. }
  49. return arrs
  50. }
  51. func FilteKey(k string) string {
  52. k = strings.TrimSpace(k)
  53. k = filterReg_3.ReplaceAllString(k, "")
  54. k = filterReg_2.ReplaceAllString(k, "")
  55. k = filterReg_1.ReplaceAllString(k, "")
  56. k = filterReg.ReplaceAllString(k, "")
  57. return k
  58. }
  59. //超过20个字,截断
  60. //返回截取后的字符串和截取掉中的前3个字
  61. func InterceptSearchKW(word string, isIntercept, isFilter bool) (b_word, a_word, s_word string) {
  62. if isFilter {
  63. word = FilteKey(word)
  64. }
  65. word = MatchSpace.ReplaceAllString(strings.TrimSpace(word), " ")
  66. words := []rune(word)
  67. if len(words) > 20 && isIntercept {
  68. b_word = string(words[:20])
  69. b_word = strings.TrimSpace(b_word)
  70. if len(words) > 23 {
  71. a_word = string(words[20:23])
  72. } else {
  73. a_word = string(words[20:])
  74. }
  75. } else {
  76. b_word = word
  77. }
  78. a_word = strings.TrimSpace(a_word)
  79. s_word = MatchSpace.ReplaceAllString(b_word, "+")
  80. return
  81. }
  82. func HttpEs(ques, analyzer, esAddress string) (res string) {
  83. var addrs []string
  84. surl := ""
  85. for _, s := range strings.Split(esAddress, ",") {
  86. addrs = append(addrs, s)
  87. }
  88. i, _ := rand.Int(rand.Reader, big.NewInt(int64(len(addrs)))) //随机
  89. surl = addrs[int(i.Int64())] + "/bidding/_analyze"
  90. URL, _ := url.Parse(surl)
  91. Q := URL.Query()
  92. Q.Add("text", ques)
  93. Q.Add("analyzer", analyzer)
  94. URL.RawQuery = Q.Encode()
  95. resp, err := http.Get(URL.String())
  96. if err != nil {
  97. log.Println("es连接失败 err1:", err)
  98. resp, err = getesResp(ques, analyzer, addrs)
  99. if err != nil {
  100. return
  101. }
  102. }
  103. result, err := ioutil.ReadAll(resp.Body)
  104. if err == nil {
  105. defer resp.Body.Close()
  106. var resmap map[string]interface{}
  107. json.Unmarshal(result, &resmap)
  108. if resmap != nil && resmap["tokens"] != nil {
  109. tokens := MC.ObjArrToMapArr(resmap["tokens"].([]interface{}))
  110. for _, v := range tokens {
  111. token := MC.ObjToString(v["token"])
  112. if len([]rune(token)) == 1 && unicode.IsLetter([]rune(token)[0]) {
  113. continue
  114. }
  115. if res != "" {
  116. res += "+"
  117. }
  118. res += token
  119. }
  120. }
  121. }
  122. return
  123. }
  124. //
  125. func getesResp(ques, analyzer string, addrs []string) (resp *http.Response, err error) {
  126. for _, v := range addrs {
  127. surl := v + "/bidding/_analyze"
  128. URL, _ := url.Parse(surl)
  129. Q := URL.Query()
  130. Q.Add("text", ques)
  131. Q.Add("analyzer", analyzer)
  132. URL.RawQuery = Q.Encode()
  133. resp, err = http.Get(URL.String())
  134. if err == nil {
  135. break
  136. }
  137. }
  138. return resp, err
  139. }
  140. //pc、微信、app 招标信息搜索
  141. const (
  142. INDEX = "bidding"
  143. TYPE = "bidding"
  144. bidSearch_sort = `{"publishtime":-1}`
  145. RedisName = "other"
  146. //招标搜索分页--每页显示数量
  147. SearchPageSize = 50
  148. //招标搜索分页--最大页数
  149. SearchMaxPageNum = 10 //免费用户500条记录
  150. SearchMaxPageNum_PAYED = 100 //付费用户5000条记录
  151. bidSearch_field_1 = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","bidamount","budget","buyerclass","filetext"`
  152. bidSearch_field = bidSearch_field_1 + `,"bidopentime","winner","buyer","projectname","projectcode","projectinfo"`
  153. )
  154. //GetBidSearchData 标信息搜索
  155. func GetBidSearchData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchList) {
  156. t := time.Now()
  157. var hightlightContent bool = false //是否高亮正文
  158. var selectTypeArr = strings.Split(in.SelectType, ",")
  159. for _, v := range selectTypeArr {
  160. if v == "detail" {
  161. hightlightContent = true
  162. break
  163. }
  164. }
  165. qstr := GetSearchQuery(in, GetBidSearchQuery(in))
  166. var start = int((in.PageNum - 1) * in.PageSize)
  167. //首页
  168. if qstr != "" && start == 0 {
  169. count = elastic.Count(INDEX, TYPE, qstr)
  170. }
  171. if count > 0 || start > 1 {
  172. field := bidSearch_field_1
  173. if start == 0 {
  174. field = bidSearch_field
  175. }
  176. var repl *[]map[string]interface{}
  177. if hightlightContent {
  178. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"detail"`, bidSearch_sort, field, start, int(in.PageSize), 115, true)
  179. } else {
  180. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, ``, bidSearch_sort, field, start, int(in.PageSize), 0, false)
  181. }
  182. logx.Info("------:", len(*repl))
  183. if repl != nil && *repl != nil && len(*repl) > 0 {
  184. BidListConvert(in.Industry, repl)
  185. for _, v := range *repl {
  186. //正文匹配检索关键词
  187. highlight, _ := v["highlight"].(map[string][]string)
  188. detail := ""
  189. for _, val := range highlight["detail"] {
  190. detail += ClearHtml.ReplaceAllString(val, "")
  191. }
  192. var searchList = &bxcore.SearchList{}
  193. searchList.Area = MC.ObjToString(v["area"])
  194. searchList.AreaUrl = IC.LabelMap[searchList.Area].Url
  195. searchList.BuyerClass = MC.ObjToString(v["buyerclass"])
  196. searchList.City = MC.ObjToString(v["city"])
  197. searchList.Detail = detail
  198. searchList.FileExists = v["filetext"] != nil
  199. searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["id"]))
  200. searchList.Industry = MC.ObjToString(v["industry"])
  201. searchList.IndustryUrl = IC.LabelMap[searchList.Industry].Url
  202. searchList.PublishTime = MC.Int64All(v["publishtime"])
  203. searchList.Subtype = MC.ObjToString(v["subtype"])
  204. searchList.SubtypeUrl = IC.LabelMap[searchList.Subtype].Url
  205. searchList.Title = MC.ObjToString(v["title"])
  206. searchList.Budget = MC.Int64All(v["budget"])
  207. searchList.Bidamount = MC.Int64All(v["bidamount"])
  208. searchList.ProjectName = MC.ObjToString(v["projectname"])
  209. searchList.ProjectCode = MC.ObjToString(v["projectcode"])
  210. searchList.ProjectInfo = &bxcore.PInfo{}
  211. if v["projectinfo"] != nil {
  212. pinfo := MC.ObjToMap(v["projectinfo"])
  213. searchList.ProjectInfo.ApproveCode = MC.ObjToString((*pinfo)["approvecode"])
  214. searchList.ProjectInfo.ApproveContent = MC.ObjToString((*pinfo)["approvecontent"])
  215. searchList.ProjectInfo.ApproveDept = MC.ObjToString((*pinfo)["approvedept"])
  216. searchList.ProjectInfo.ApproveStatus = MC.ObjToString((*pinfo)["approvestatus"])
  217. searchList.ProjectInfo.ProjectType = MC.ObjToString((*pinfo)["projecttype"])
  218. searchList.ProjectInfo.ApproveNumber = MC.ObjToString((*pinfo)["approvenumber"])
  219. searchList.ProjectInfo.ApproveTime = MC.ObjToString((*pinfo)["approvetime"])
  220. }
  221. searchList.Winner = MC.ObjToString(v["winner"])
  222. searchList.Buyer = MC.ObjToString(v["buyer"])
  223. searchList.BidopenTime = MC.Int64All(v["bidopentime"])
  224. list = append(list, searchList)
  225. }
  226. }
  227. logx.Info("关键词 -1- 查询耗时:", time.Since(t).Seconds())
  228. MakeCollection(in.UserId, list)
  229. logx.Info("=====:", len(list))
  230. }
  231. logx.Info("关键词 查询耗时:", time.Since(t).Seconds())
  232. return
  233. }
  234. func GetBidSearchQuery(in *bxcore.SearchReq) string {
  235. query := ``
  236. //省份
  237. area := in.Province
  238. if area != "" {
  239. query += `{"terms":{"area":[`
  240. for k, v := range strings.Split(area, ",") {
  241. if k > 0 {
  242. query += `,`
  243. }
  244. query += `"` + v + `"`
  245. }
  246. query += `]}}`
  247. }
  248. //
  249. city := in.City
  250. if city != "" {
  251. if len(query) > 0 {
  252. query += ","
  253. }
  254. query += `{"terms":{"city":[`
  255. for k, v := range strings.Split(city, ",") {
  256. if k > 0 {
  257. query += `,`
  258. }
  259. query += `"` + v + `"`
  260. }
  261. query += `]}}`
  262. }
  263. //发布时间
  264. publishtime := in.PublishTime
  265. if publishtime != "" && len(strings.Split(publishtime, "-")) > 1 {
  266. if len(query) > 0 {
  267. query += ","
  268. }
  269. starttime := strings.Split(publishtime, "-")[0]
  270. endtime := strings.Split(publishtime, "-")[1]
  271. query += `{"range":{"publishtime":{`
  272. if starttime != "" {
  273. query += `"gte":` + starttime
  274. }
  275. if starttime != "" && endtime != "" {
  276. query += `,`
  277. }
  278. if endtime != "" {
  279. query += `"lt":` + endtime
  280. }
  281. query += `}}}`
  282. }
  283. //信息类型
  284. subtype := in.Subtype
  285. if subtype != "" {
  286. if len(query) > 0 {
  287. query += ","
  288. }
  289. query += `{"terms":{"subtype":[`
  290. for k, v := range strings.Split(subtype, ",") {
  291. if k > 0 {
  292. query += `,`
  293. }
  294. query += `"` + v + `"`
  295. }
  296. query += `]}}`
  297. }
  298. //
  299. //if winner != "" {
  300. // if len(query) > 0 {
  301. // query += ","
  302. // }
  303. // query += `{"terms":{"s_winner":[`
  304. // for k, v := range strings.Split(winner, ",") {
  305. // if k > 0 {
  306. // query += `,`
  307. // }
  308. // query += `"` + v + `"`
  309. // }
  310. // query += `]}}`
  311. //}
  312. //采购单位类型
  313. buyerclass := in.BuyerClass
  314. if buyerclass != "" {
  315. if len(query) > 0 {
  316. query += ","
  317. }
  318. query += `{"terms":{"buyerclass":[`
  319. for k, v := range strings.Split(buyerclass, ",") {
  320. if k > 0 {
  321. query += `,`
  322. }
  323. query += `"` + v + `"`
  324. }
  325. query += `]}}`
  326. }
  327. return query
  328. }
  329. func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
  330. multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
  331. query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
  332. query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
  333. query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
  334. query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
  335. query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
  336. gte := `"gte": %s`
  337. lte := `"lte": %s`
  338. musts, must_not := []string{}, []string{}
  339. if mustquery != "" {
  340. musts = append(musts, mustquery)
  341. }
  342. selectTypeArr := strings.Split(in.SelectType, ",")
  343. var findfields string
  344. if selectTypeArr == nil || len(selectTypeArr) == 0 {
  345. findfields = `"title"`
  346. } else {
  347. findfields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
  348. }
  349. var isFileSearch bool = false //搜索范围是否有附件选择
  350. //此时关键词中间有+进行隔离
  351. if in.KeyWords != "" {
  352. if strings.Contains(findfields, "filetext") { //搜索范围选择附件,是否有附件条件无效;
  353. isFileSearch = true
  354. }
  355. shoulds := []string{}
  356. var switchBool = strings.Contains(findfields, "detail") && strings.Contains(findfields, "title") && IC.C.SearchTypeSwitch
  357. log.Println("in.KeyWords:", in.KeyWords)
  358. for _, v := range strings.Split(in.KeyWords, "+") {
  359. //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
  360. if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
  361. if strings.Contains(findfields, `"title",`) {
  362. findfields = strings.Replace(findfields, `"title",`, ``, -1)
  363. } else if strings.Contains(findfields, `,"title"`) {
  364. findfields = strings.Replace(findfields, `,"title"`, ``, -1)
  365. }
  366. }
  367. keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  368. shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
  369. }
  370. musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
  371. }
  372. if in.Industry != "" {
  373. industrys := strings.Split(in.Industry, ",")
  374. musts = append(musts, fmt.Sprintf(query_bool_must, `"`+strings.Join(industrys, `","`)+`"`))
  375. }
  376. //价格
  377. if in.Price != "" && len(strings.Split(in.Price, "-")) > 1 {
  378. minprice, maxprice := strings.Split(in.Price, "-")[0], strings.Split(in.Price, "-")[1]
  379. if minprice != "" || maxprice != "" {
  380. sq := ``
  381. if minprice != "" {
  382. min, _ := strconv.ParseFloat(minprice, 64)
  383. minprice = fmt.Sprintf("%.0f", min*10000)
  384. if minprice == "0" {
  385. minprice = ""
  386. }
  387. }
  388. if maxprice != "" {
  389. max, _ := strconv.ParseFloat(maxprice, 64)
  390. maxprice = fmt.Sprintf("%.0f", max*10000)
  391. if maxprice == "0" {
  392. maxprice = ""
  393. }
  394. }
  395. if minprice != "" {
  396. sq += fmt.Sprintf(gte, minprice)
  397. }
  398. if minprice != "" && maxprice != "" {
  399. sq += `,`
  400. }
  401. if maxprice != "" {
  402. sq += fmt.Sprintf(lte, maxprice)
  403. }
  404. if minprice != "" || maxprice != "" {
  405. query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_bools_must, sq, sq))
  406. musts = append(musts, query_price)
  407. }
  408. }
  409. }
  410. hasBuyerTel := in.BuyerTel
  411. if hasBuyerTel != "" {
  412. if hasBuyerTel == "y" {
  413. must_not = append(must_not, fmt.Sprintf(query_missing, "buyertel"))
  414. } else {
  415. musts = append(musts, fmt.Sprintf(query_missing, "buyertel"))
  416. }
  417. }
  418. hasWinnerTel := in.WinnerTel
  419. if hasWinnerTel != "" {
  420. if hasWinnerTel == "y" {
  421. must_not = append(must_not, fmt.Sprintf(query_missing, "winnertel"))
  422. } else {
  423. musts = append(musts, fmt.Sprintf(query_missing, "winnertel"))
  424. }
  425. }
  426. //排除词
  427. notkey := in.ExclusionWords
  428. if notkey = strings.TrimSpace(notkey); notkey != "" {
  429. notkey_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  430. notkey_must_not := []string{}
  431. for _, v := range strings.Split(notkey, " ") {
  432. v = strings.TrimSpace(v)
  433. if v == "" {
  434. continue
  435. }
  436. notkey_must_not = append(notkey_must_not, fmt.Sprintf(notkey_multi_match, elastic.ReplaceYH(v)))
  437. }
  438. must_not = append(must_not, fmt.Sprintf(query_bool_should, strings.Join(notkey_must_not, ",")))
  439. }
  440. //
  441. fileExists := in.FileExists
  442. if !isFileSearch && fileExists != "" {
  443. if fileExists == "1" { //有附件
  444. must_not = append(must_not, fmt.Sprintf(query_missing, "filetext"))
  445. } else if fileExists == "-1" { //无附件
  446. musts = append(musts, fmt.Sprintf(query_missing, "filetext"))
  447. }
  448. }
  449. qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(must_not, ","))
  450. logx.Info(qstr)
  451. return
  452. }
  453. /*
  454. * 结果列表转换,目前只换行行业字段
  455. * 所有的招标搜索都要调用此方法,列表中有展示行业的也可以用
  456. * industry 搜索条件中的行业,默认为空
  457. */
  458. func BidListConvert(industry string, res *[]map[string]interface{}) {
  459. if res == nil {
  460. return
  461. }
  462. commonSubstring := func(v string) (value string) {
  463. bcs := strings.Split(v, "_")
  464. if len(bcs) == 1 {
  465. value = bcs[0]
  466. } else if len(bcs) == 2 {
  467. value = bcs[0]
  468. if strings.TrimSpace(value) == "" {
  469. value = bcs[0]
  470. }
  471. }
  472. return
  473. }
  474. for _, v := range *res {
  475. v["id"] = v["_id"]
  476. delete(v, "_id")
  477. budget, _ := v["budget"].(float64)
  478. bidamount, _ := v["bidamount"].(float64)
  479. if budget == 0 || strings.TrimSpace(fmt.Sprint(v["budget"])) == "" {
  480. delete(v, "budget")
  481. }
  482. if bidamount == 0 || strings.TrimSpace(fmt.Sprint(v["bidamount"])) == "" {
  483. delete(v, "bidamount")
  484. }
  485. value := ""
  486. subscopeclass, _ := v["s_subscopeclass"].(string)
  487. subscopeclass = strings.Trim(subscopeclass, ",")
  488. bct := strings.Split(subscopeclass, ",")
  489. if bct == nil || len(bct) == 0 {
  490. continue
  491. }
  492. //搜索条件中没有行业的话,取查询结果中第一个行业
  493. if industry == "" {
  494. value = commonSubstring(bct[0])
  495. } else { //搜索条件中有行业的话,取行业中和搜索条件相对应的第一个
  496. industrys := strings.Split(industry, ",")
  497. L:
  498. for _, bc := range bct {
  499. for _, is := range industrys {
  500. if bc == is {
  501. value = commonSubstring(bc)
  502. break L
  503. }
  504. }
  505. }
  506. }
  507. if strings.TrimSpace(value) == "" {
  508. continue
  509. }
  510. v["industry"] = value
  511. }
  512. }
  513. //是否收藏
  514. func MakeCollection(userId string, list []*bxcore.SearchList) {
  515. if list == nil || len(list) == 0 {
  516. return
  517. }
  518. param := []interface{}{userId}
  519. wh := []string{}
  520. for _, v := range list {
  521. array := ME.DecodeArticleId2ByCheck(v.Id)
  522. if len(array) == 1 && array[0] != "" {
  523. param = append(param, array[0])
  524. wh = append(wh, "?")
  525. }
  526. }
  527. if len(wh) > 0 {
  528. result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
  529. bid_map := map[string]bool{}
  530. if result != nil {
  531. for _, v := range *result {
  532. bid_map[ME.EncodeArticleId2ByCheck(MC.ObjToString(v["bid"]))] = true
  533. }
  534. }
  535. for _, v := range list {
  536. if bid_map[v.Id] {
  537. v.IsCollected = true
  538. }
  539. }
  540. }
  541. }
  542. //默认查询缓存数据
  543. func SearchCahcheData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchList) {
  544. //最新招标信息
  545. findfields := `"title"`
  546. qstr := GetSearchQuery(in, GetBidSearchQuery(in))
  547. //首页
  548. if in.PageNum == 1 {
  549. count = elastic.Count(INDEX, TYPE, qstr)
  550. }
  551. if count > 0 || in.PageNum > 1 {
  552. repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, int(in.PageNum), int(in.PageSize), 0, false)
  553. if repl != nil && *repl != nil && len(*repl) > 0 {
  554. BidListConvert(in.Industry, repl)
  555. for _, v := range *repl {
  556. var searchList = &bxcore.SearchList{}
  557. searchList.Area = MC.ObjToString(v["area"])
  558. searchList.AreaUrl = IC.LabelMap[searchList.Area].Url
  559. searchList.BuyerClass = MC.ObjToString(v["buyerclass"])
  560. searchList.City = MC.ObjToString(v["city"])
  561. searchList.FileExists = v["filetext"] != nil
  562. searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["id"]))
  563. searchList.Industry = MC.ObjToString(v["industry"])
  564. searchList.IndustryUrl = IC.LabelMap[searchList.Industry].Url
  565. searchList.PublishTime = MC.Int64All(v["publishtime"])
  566. searchList.Subtype = MC.ObjToString(v["subtype"])
  567. searchList.SubtypeUrl = IC.LabelMap[searchList.Subtype].Url
  568. searchList.Title = MC.ObjToString(v["title"])
  569. searchList.Budget = MC.Int64All(v["budget"])
  570. searchList.Bidamount = MC.Int64All(v["bidamount"])
  571. searchList.ProjectName = MC.ObjToString(v["projectname"])
  572. searchList.ProjectCode = MC.ObjToString(v["projectcode"])
  573. searchList.ProjectInfo = &bxcore.PInfo{}
  574. if v["projectinfo"] != nil {
  575. pinfo := MC.ObjToMap(v["projectinfo"])
  576. searchList.ProjectInfo.ApproveCode = MC.ObjToString((*pinfo)["approvecode"])
  577. searchList.ProjectInfo.ApproveContent = MC.ObjToString((*pinfo)["approvecontent"])
  578. searchList.ProjectInfo.ApproveDept = MC.ObjToString((*pinfo)["approvedept"])
  579. searchList.ProjectInfo.ApproveStatus = MC.ObjToString((*pinfo)["approvestatus"])
  580. searchList.ProjectInfo.ProjectType = MC.ObjToString((*pinfo)["projecttype"])
  581. searchList.ProjectInfo.ApproveNumber = MC.ObjToString((*pinfo)["approvenumber"])
  582. searchList.ProjectInfo.ApproveTime = MC.ObjToString((*pinfo)["approvetime"])
  583. }
  584. searchList.Winner = MC.ObjToString(v["winner"])
  585. searchList.Buyer = MC.ObjToString(v["buyer"])
  586. searchList.BidopenTime = MC.Int64All(v["bidopentime"])
  587. list = append(list, searchList)
  588. }
  589. }
  590. }
  591. return
  592. }