search.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. for _, v := range strings.Split(in.KeyWords, "+") {
  358. //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
  359. if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
  360. if strings.Contains(findfields, `"title",`) {
  361. findfields = strings.Replace(findfields, `"title",`, ``, -1)
  362. } else if strings.Contains(findfields, `,"title"`) {
  363. findfields = strings.Replace(findfields, `,"title"`, ``, -1)
  364. }
  365. }
  366. keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  367. shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
  368. }
  369. musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
  370. }
  371. if in.Industry != "" {
  372. industrys := strings.Split(in.Industry, ",")
  373. musts = append(musts, fmt.Sprintf(query_bool_must, `"`+strings.Join(industrys, `","`)+`"`))
  374. }
  375. //价格
  376. if in.Price != "" && len(strings.Split(in.Price, "-")) > 1 {
  377. minprice, maxprice := strings.Split(in.Price, "-")[0], strings.Split(in.Price, "-")[1]
  378. if minprice != "" || maxprice != "" {
  379. sq := ``
  380. if minprice != "" {
  381. min, _ := strconv.ParseFloat(minprice, 64)
  382. minprice = fmt.Sprintf("%.0f", min*10000)
  383. if minprice == "0" {
  384. minprice = ""
  385. }
  386. }
  387. if maxprice != "" {
  388. max, _ := strconv.ParseFloat(maxprice, 64)
  389. maxprice = fmt.Sprintf("%.0f", max*10000)
  390. if maxprice == "0" {
  391. maxprice = ""
  392. }
  393. }
  394. if minprice != "" {
  395. sq += fmt.Sprintf(gte, minprice)
  396. }
  397. if minprice != "" && maxprice != "" {
  398. sq += `,`
  399. }
  400. if maxprice != "" {
  401. sq += fmt.Sprintf(lte, maxprice)
  402. }
  403. if minprice != "" || maxprice != "" {
  404. query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_bools_must, sq, sq))
  405. musts = append(musts, query_price)
  406. }
  407. }
  408. }
  409. hasBuyerTel := in.BuyerTel
  410. if hasBuyerTel != "" {
  411. if hasBuyerTel == "y" {
  412. must_not = append(must_not, fmt.Sprintf(query_missing, "buyertel"))
  413. } else {
  414. musts = append(musts, fmt.Sprintf(query_missing, "buyertel"))
  415. }
  416. }
  417. hasWinnerTel := in.WinnerTel
  418. if hasWinnerTel != "" {
  419. if hasWinnerTel == "y" {
  420. must_not = append(must_not, fmt.Sprintf(query_missing, "winnertel"))
  421. } else {
  422. musts = append(musts, fmt.Sprintf(query_missing, "winnertel"))
  423. }
  424. }
  425. //排除词
  426. notkey := in.ExclusionWords
  427. if notkey = strings.TrimSpace(notkey); notkey != "" {
  428. notkey_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  429. notkey_must_not := []string{}
  430. for _, v := range strings.Split(notkey, " ") {
  431. v = strings.TrimSpace(v)
  432. if v == "" {
  433. continue
  434. }
  435. notkey_must_not = append(notkey_must_not, fmt.Sprintf(notkey_multi_match, elastic.ReplaceYH(v)))
  436. }
  437. must_not = append(must_not, fmt.Sprintf(query_bool_should, strings.Join(notkey_must_not, ",")))
  438. }
  439. //
  440. fileExists := in.FileExists
  441. if !isFileSearch && fileExists != "" {
  442. if fileExists == "1" { //有附件
  443. must_not = append(must_not, fmt.Sprintf(query_missing, "filetext"))
  444. } else if fileExists == "-1" { //无附件
  445. musts = append(musts, fmt.Sprintf(query_missing, "filetext"))
  446. }
  447. }
  448. qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(must_not, ","))
  449. logx.Info(qstr)
  450. return
  451. }
  452. /*
  453. * 结果列表转换,目前只换行行业字段
  454. * 所有的招标搜索都要调用此方法,列表中有展示行业的也可以用
  455. * industry 搜索条件中的行业,默认为空
  456. */
  457. func BidListConvert(industry string, res *[]map[string]interface{}) {
  458. if res == nil {
  459. return
  460. }
  461. commonSubstring := func(v string) (value string) {
  462. bcs := strings.Split(v, "_")
  463. if len(bcs) == 1 {
  464. value = bcs[0]
  465. } else if len(bcs) == 2 {
  466. value = bcs[0]
  467. if strings.TrimSpace(value) == "" {
  468. value = bcs[0]
  469. }
  470. }
  471. return
  472. }
  473. for _, v := range *res {
  474. v["id"] = v["_id"]
  475. delete(v, "_id")
  476. budget, _ := v["budget"].(float64)
  477. bidamount, _ := v["bidamount"].(float64)
  478. if budget == 0 || strings.TrimSpace(fmt.Sprint(v["budget"])) == "" {
  479. delete(v, "budget")
  480. }
  481. if bidamount == 0 || strings.TrimSpace(fmt.Sprint(v["bidamount"])) == "" {
  482. delete(v, "bidamount")
  483. }
  484. value := ""
  485. subscopeclass, _ := v["s_subscopeclass"].(string)
  486. subscopeclass = strings.Trim(subscopeclass, ",")
  487. bct := strings.Split(subscopeclass, ",")
  488. if bct == nil || len(bct) == 0 {
  489. continue
  490. }
  491. //搜索条件中没有行业的话,取查询结果中第一个行业
  492. if industry == "" {
  493. value = commonSubstring(bct[0])
  494. } else { //搜索条件中有行业的话,取行业中和搜索条件相对应的第一个
  495. industrys := strings.Split(industry, ",")
  496. L:
  497. for _, bc := range bct {
  498. for _, is := range industrys {
  499. if bc == is {
  500. value = commonSubstring(bc)
  501. break L
  502. }
  503. }
  504. }
  505. }
  506. if strings.TrimSpace(value) == "" {
  507. continue
  508. }
  509. v["industry"] = value
  510. }
  511. }
  512. //是否收藏
  513. func MakeCollection(userId string, list []*bxcore.SearchList) {
  514. if list == nil || len(list) == 0 {
  515. return
  516. }
  517. param := []interface{}{userId}
  518. wh := []string{}
  519. for _, v := range list {
  520. array := ME.DecodeArticleId2ByCheck(v.Id)
  521. if len(array) == 1 && array[0] != "" {
  522. param = append(param, array[0])
  523. wh = append(wh, "?")
  524. }
  525. }
  526. if len(wh) > 0 {
  527. result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
  528. bid_map := map[string]bool{}
  529. if result != nil {
  530. for _, v := range *result {
  531. bid_map[ME.EncodeArticleId2ByCheck(MC.ObjToString(v["bid"]))] = true
  532. }
  533. }
  534. for _, v := range list {
  535. if bid_map[v.Id] {
  536. v.IsCollected = true
  537. }
  538. }
  539. }
  540. }
  541. //默认查询缓存数据
  542. func SearchCahcheData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchList) {
  543. //最新招标信息
  544. findfields := `"title"`
  545. qstr := GetSearchQuery(in, GetBidSearchQuery(in))
  546. //首页
  547. if in.PageNum == 1 {
  548. count = elastic.Count(INDEX, TYPE, qstr)
  549. }
  550. if count > 0 || in.PageNum > 1 {
  551. repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, int(in.PageNum), int(in.PageSize), 0, false)
  552. if repl != nil && *repl != nil && len(*repl) > 0 {
  553. BidListConvert(in.Industry, repl)
  554. for _, v := range *repl {
  555. var searchList = &bxcore.SearchList{}
  556. searchList.Area = MC.ObjToString(v["area"])
  557. searchList.AreaUrl = IC.LabelMap[searchList.Area].Url
  558. searchList.BuyerClass = MC.ObjToString(v["buyerclass"])
  559. searchList.City = MC.ObjToString(v["city"])
  560. searchList.FileExists = v["filetext"] != nil
  561. searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["id"]))
  562. searchList.Industry = MC.ObjToString(v["industry"])
  563. searchList.IndustryUrl = IC.LabelMap[searchList.Industry].Url
  564. searchList.PublishTime = MC.Int64All(v["publishtime"])
  565. searchList.Subtype = MC.ObjToString(v["subtype"])
  566. searchList.SubtypeUrl = IC.LabelMap[searchList.Subtype].Url
  567. searchList.Title = MC.ObjToString(v["title"])
  568. searchList.Budget = MC.Int64All(v["budget"])
  569. searchList.Bidamount = MC.Int64All(v["bidamount"])
  570. searchList.ProjectName = MC.ObjToString(v["projectname"])
  571. searchList.ProjectCode = MC.ObjToString(v["projectcode"])
  572. searchList.ProjectInfo = &bxcore.PInfo{}
  573. if v["projectinfo"] != nil {
  574. pinfo := MC.ObjToMap(v["projectinfo"])
  575. searchList.ProjectInfo.ApproveCode = MC.ObjToString((*pinfo)["approvecode"])
  576. searchList.ProjectInfo.ApproveContent = MC.ObjToString((*pinfo)["approvecontent"])
  577. searchList.ProjectInfo.ApproveDept = MC.ObjToString((*pinfo)["approvedept"])
  578. searchList.ProjectInfo.ApproveStatus = MC.ObjToString((*pinfo)["approvestatus"])
  579. searchList.ProjectInfo.ProjectType = MC.ObjToString((*pinfo)["projecttype"])
  580. searchList.ProjectInfo.ApproveNumber = MC.ObjToString((*pinfo)["approvenumber"])
  581. searchList.ProjectInfo.ApproveTime = MC.ObjToString((*pinfo)["approvetime"])
  582. }
  583. searchList.Winner = MC.ObjToString(v["winner"])
  584. searchList.Buyer = MC.ObjToString(v["buyer"])
  585. searchList.BidopenTime = MC.Int64All(v["bidopentime"])
  586. list = append(list, searchList)
  587. }
  588. }
  589. }
  590. return
  591. }