search.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. package es
  2. import (
  3. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/bxcore"
  4. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/entity"
  5. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
  6. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/util"
  7. "fmt"
  8. "strconv"
  9. "strings"
  10. "time"
  11. MC "app.yhyue.com/moapp/jybase/common"
  12. elastic "app.yhyue.com/moapp/jybase/es"
  13. "log"
  14. )
  15. // GetSearchQuery 整理关键词等查询条件
  16. func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
  17. var (
  18. //搜索范围是否只有附件
  19. //搜索范围只选择附件,是否有附件条件无效;
  20. isFileSearch = in.SelectType == "filetext"
  21. wordsMusts, wordsShould, musts, mustNot []string
  22. findFields string
  23. selectTypeArr = strings.Split(in.SelectType, ",")
  24. isLogin = in.UserId != ""
  25. )
  26. if selectTypeArr == nil || len(selectTypeArr) == 0 {
  27. findFields = `"title"`
  28. } else {
  29. findFields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
  30. }
  31. switchBool := strings.Contains(findFields, "detail") && strings.Contains(findFields, "title") && IC.C.SearchTypeSwitch
  32. if mustQuery != "" {
  33. musts = append(musts, mustQuery)
  34. }
  35. //采购单位
  36. if in.Buyer != "" {
  37. musts = append(musts, util.GetMatchArrSql("buyer.mbuyer", strings.Split(in.Buyer, ",")...))
  38. }
  39. //中标单位
  40. if in.Winner != "" {
  41. musts = append(musts, util.GetMatchArrSql("s_winner.mwinner", strings.Split(in.Winner, ",")...))
  42. }
  43. //代理机构
  44. if in.Agency != "" {
  45. musts = append(musts, util.GetMatchArrSql("agency.magency", strings.Split(in.Agency, ",")...))
  46. }
  47. //此时关键词中间有IC.C.JYKeyMark进行隔离
  48. if in.KeyWords != "" {
  49. var (
  50. keyWordsMusts []string
  51. )
  52. for _, v := range strings.Split(in.KeyWords, IC.C.JYKeyMark) {
  53. if elastic.ReplaceYH(v) == "" {
  54. continue
  55. }
  56. //单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
  57. //detail 正文不支持单字查询
  58. if len([]rune(elastic.ReplaceYH(v))) == 1 && DetailFileORTitle(findFields) {
  59. findFields += `,"title"`
  60. } else if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
  61. //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
  62. if strings.Contains(findFields, `"title",`) {
  63. findFields = strings.Replace(findFields, `"title",`, ``, -1)
  64. } else if strings.Contains(findFields, `,"title"`) {
  65. findFields = strings.Replace(findFields, `,"title"`, ``, -1)
  66. }
  67. }
  68. keyWordsMusts = append(keyWordsMusts, fmt.Sprintf(fmt.Sprintf(MultiMatch, "%s", findFields), elastic.ReplaceYH(v)))
  69. }
  70. //搜索关键词模式;默认0:包含所有,1:包含任意
  71. if in.WordsMode == 1 {
  72. wordsShould = append(wordsShould, fmt.Sprintf(elastic.NgramMust, strings.Join(keyWordsMusts, ",")))
  73. } else {
  74. wordsMusts = append(wordsMusts, keyWordsMusts...)
  75. }
  76. }
  77. //附加词
  78. if in.AdditionalWords != "" {
  79. //多组附加词,每组间,号隔开。每组内如果关键词中间有空格,自动分词
  80. var (
  81. addWordsMusts []string
  82. )
  83. for _, aws := range strings.Split(in.AdditionalWords, ",") {
  84. var (
  85. addWordsMust []string
  86. )
  87. for _, v := range strings.Split(aws, IC.C.JYKeyMark) {
  88. if elastic.ReplaceYH(v) == "" {
  89. continue
  90. }
  91. //单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
  92. //detail 正文不支持单字查询
  93. if len([]rune(elastic.ReplaceYH(v))) == 1 && DetailFileORTitle(findFields) {
  94. findFields += `,"title"`
  95. } else if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
  96. //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
  97. if strings.Contains(findFields, `"title",`) {
  98. findFields = strings.Replace(findFields, `"title",`, ``, -1)
  99. } else if strings.Contains(findFields, `,"title"`) {
  100. findFields = strings.Replace(findFields, `,"title"`, ``, -1)
  101. }
  102. }
  103. addWordsMust = append(addWordsMust, fmt.Sprintf(fmt.Sprintf(MultiMatch, "%s", findFields), elastic.ReplaceYH(v)))
  104. addWordsMusts = append(addWordsMusts, addWordsMust...)
  105. if in.WordsMode == 0 {
  106. wordsMusts = append(wordsMusts, addWordsMust...)
  107. }
  108. addWordsMust = []string{}
  109. }
  110. //搜索关键词模式;默认0:包含所有,1:包含任意
  111. if in.WordsMode == 1 {
  112. wordsShould = append(wordsShould, fmt.Sprintf(elastic.NgramMust, strings.Join(addWordsMusts, ",")))
  113. addWordsMusts = []string{}
  114. }
  115. }
  116. }
  117. //搜索关键词模式;默认0:包含所有,1:包含任意
  118. //包含任意一组
  119. if len(wordsShould) > 0 {
  120. musts = append(musts, fmt.Sprintf(QueryBoolShould, strings.Join(wordsShould, ",")))
  121. } else if len(wordsMusts) > 0 {
  122. musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(wordsMusts, ",")))
  123. }
  124. //排除词
  125. if notKey := strings.TrimSpace(in.ExclusionWords); notKey != "" {
  126. notKeyMultiMatch := fmt.Sprintf(MultiMatch, "%s", findFields)
  127. var notKeyMustNot []string
  128. //多组排除词
  129. for _, nks := range strings.Split(notKey, ",") {
  130. //单组排除词 空格分割
  131. for _, v := range strings.Split(nks, IC.C.JYKeyMark) {
  132. v = strings.TrimSpace(v)
  133. if v == "" {
  134. continue
  135. }
  136. if len([]rune(elastic.ReplaceYH(v))) == 1 {
  137. //单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
  138. if DetailFileORTitle(findFields) {
  139. notKeyMultiMatch = fmt.Sprintf(MultiMatch, "%s", findFields+`,"title"`)
  140. }
  141. }
  142. notKeyMustNot = append(notKeyMustNot, fmt.Sprintf(notKeyMultiMatch, elastic.ReplaceYH(v)))
  143. }
  144. }
  145. mustNot = append(mustNot, fmt.Sprintf(QueryBoolShould, strings.Join(notKeyMustNot, ",")))
  146. }
  147. //行业
  148. if in.Industry != "" && isLogin {
  149. musts = append(musts, fmt.Sprintf(QueryBoolMustA, "s_subscopeclass", `"`+strings.ReplaceAll(in.Industry, ",", `","`)+`"`))
  150. //var (
  151. // topSC []string
  152. // topQT bool
  153. //)
  154. //for _, sv := range strings.Split(in.Industry, ",") {
  155. // if strings.Contains(sv, "其他") {
  156. // if len(strings.Split(sv, "_")) > 1 {
  157. // topSC = append(topSC, strings.Split(sv, "_")[0])
  158. // } else {
  159. // topQT = true
  160. // }
  161. // }
  162. //}
  163. ////一级行业-其他
  164. //if topQT {
  165. // mustNot = append(mustNot, `{"exists": {"field": "s_topscopeclass"}}`)
  166. //}
  167. //if len(topSC) > 0 {
  168. // //二级行业-其他
  169. // musts = append(musts, fmt.Sprintf(queryBoolMustScopeClass, `"`+strings.ReplaceAll(in.Industry, ",", `","`)+`"`, `"`+strings.Join(topSC, `","`)+`"`))
  170. //} else {
  171. // musts = append(musts, fmt.Sprintf(QueryBoolMustA, "s_subscopeclass", `"`+strings.ReplaceAll(in.Industry, ",", `","`)+`"`))
  172. //}
  173. }
  174. //价格
  175. if in.Price != "" && len(strings.Split(in.Price, "-")) > 1 {
  176. minPrice, maxPrice := strings.Split(in.Price, "-")[0], strings.Split(in.Price, "-")[1]
  177. if minPrice != "" || maxPrice != "" {
  178. sq := ``
  179. if minPrice != "" {
  180. min, _ := strconv.ParseFloat(minPrice, 64)
  181. minPrice = fmt.Sprintf("%.0f", min*10000)
  182. if minPrice == "0" {
  183. minPrice = ""
  184. }
  185. }
  186. if maxPrice != "" {
  187. max, _ := strconv.ParseFloat(maxPrice, 64)
  188. maxPrice = fmt.Sprintf("%.0f", max*10000)
  189. if maxPrice == "0" {
  190. maxPrice = ""
  191. }
  192. }
  193. if minPrice != "" {
  194. sq += fmt.Sprintf(gte, minPrice)
  195. }
  196. if minPrice != "" && maxPrice != "" {
  197. sq += `,`
  198. }
  199. if maxPrice != "" {
  200. sq += fmt.Sprintf(lte, maxPrice)
  201. }
  202. if minPrice != "" || maxPrice != "" {
  203. query_price := fmt.Sprintf(QueryBoolShould, fmt.Sprintf(queryBoolMustBoolShould, sq, sq))
  204. musts = append(musts, query_price)
  205. }
  206. }
  207. }
  208. //采购单位联系方式
  209. hasBuyerTel := in.BuyerTel
  210. if hasBuyerTel != "" {
  211. if hasBuyerTel == "y" {
  212. musts = append(musts, fmt.Sprintf(queryExists, "buyertel"))
  213. } else {
  214. mustNot = append(mustNot, fmt.Sprintf(queryExists, "buyertel"))
  215. }
  216. }
  217. //中标企业联系方式
  218. hasWinnerTel := in.WinnerTel
  219. if hasWinnerTel != "" {
  220. if hasWinnerTel == "y" {
  221. musts = append(musts, fmt.Sprintf(queryExists, "winnertel"))
  222. } else {
  223. mustNot = append(mustNot, fmt.Sprintf(queryExists, "winnertel"))
  224. }
  225. }
  226. //移动融创
  227. if in.MobileTag != nil && len(in.MobileTag) > 0 && in.IsPay { //仅付费bidding表有此字段
  228. musts = append(musts, fmt.Sprintf(QueryBoolMustA, "mobile_tag", `"`+strings.Join(in.MobileTag, `","`)+`"`))
  229. }
  230. if isLogin { //需要登录
  231. //电脑端 物业专版BI
  232. if in.BidField == "BIProperty" {
  233. if !entity.MobileReg.MatchString(in.UserAgent) {
  234. musts = append(musts, fmt.Sprintf(QueryBoolMustA, "tag_topinformation", `"情报_物业"`))
  235. //物业业态
  236. if in.PropertyForm != "" {
  237. arr := []string{}
  238. for _, v := range strings.Split(in.PropertyForm, ",") {
  239. arr = append(arr, fmt.Sprintf(`"%s"`, v))
  240. }
  241. musts = append(musts, fmt.Sprintf(QueryBoolShould, fmt.Sprintf(`{"terms":{"tag_set.wuye.property_form":[%s]}}`, strings.Join(arr, ","))))
  242. }
  243. //业务类型
  244. if in.SubInformation != "" {
  245. arr := []string{}
  246. for _, v := range strings.Split(in.SubInformation, ",") {
  247. arr = append(arr, fmt.Sprintf(`"%s"`, v))
  248. }
  249. musts = append(musts, fmt.Sprintf(QueryBoolShould, fmt.Sprintf(`{"terms":{"tag_subinformation":[%s]}}`, strings.Join(arr, ","))))
  250. }
  251. //价格区间
  252. if in.Scale != "" {
  253. arr := []string{}
  254. for _, v := range strings.Split(in.Scale, ",") {
  255. arr = append(arr, fmt.Sprintf(`"%s"`, v))
  256. }
  257. musts = append(musts, fmt.Sprintf(QueryBoolShould, fmt.Sprintf(`{"terms":{"tag_set.wuye.scale":[%s]}}`, strings.Join(arr, ","))))
  258. }
  259. //合同周期
  260. if in.Period != "" {
  261. arr := []string{}
  262. for _, v := range strings.Split(in.Period, ",") {
  263. arr = append(arr, fmt.Sprintf(`"%s"`, v))
  264. }
  265. musts = append(musts, fmt.Sprintf(QueryBoolShould, fmt.Sprintf(`{"terms":{"tag_set.wuye.period":[%s]}}`, strings.Join(arr, ","))))
  266. }
  267. //换手率
  268. if in.ChangeHand != 0 {
  269. if in.ChangeHand > 0 {
  270. //存在
  271. musts = append(musts, `{"range":{"tag_set.wuye.changehand":{"gt":0.3}}}`)
  272. }
  273. }
  274. if in.FileExists != "" {
  275. if in.FileExists == "1" {
  276. //存在
  277. musts = append(musts, fmt.Sprintf(QueryBoolMustA, "tag_set.wuye.isfile", `"63"`))
  278. } else {
  279. //不存在
  280. mustNot = append(mustNot, fmt.Sprintf(queryExists, "tag_set.wuye.isfile"))
  281. }
  282. }
  283. }
  284. } else {
  285. //附件--非BI
  286. fileExists := in.FileExists
  287. if !isFileSearch && fileExists != "" {
  288. if fileExists == "1" { //有附件
  289. musts = append(musts, fmt.Sprintf(QueryBoolMustTermBool, "isValidFile", true))
  290. } else if fileExists == "-1" { //无附件
  291. mustNot = append(mustNot, fmt.Sprintf(QueryBoolMustTermBool, "isValidFile", true))
  292. }
  293. }
  294. if in.BidField == "medical" { // 如果是领域化数据则需要加标签
  295. musts = append(musts, fmt.Sprintf(queryBoolMustTermDomain, "0101"))
  296. }
  297. }
  298. }
  299. //in.BidField 剑鱼默认招标信息搜索 此参数为空**
  300. qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(mustNot, ","))
  301. log.Println("qstr:", qstr)
  302. return
  303. }
  304. // GetBidSearchQuery 整理地区、城市、发布时间、信息类型、采购单位类型 查询条件
  305. func GetBidSearchQuery(in *bxcore.SearchReq) string {
  306. query := ``
  307. //省份
  308. area := in.Province
  309. isLogin := in.UserId != ""
  310. if area != "" {
  311. query += `{"terms":{"area":[`
  312. for k, v := range strings.Split(area, ",") {
  313. if k > 0 {
  314. query += `,`
  315. }
  316. query += `"` + v + `"`
  317. }
  318. query += `]}}`
  319. }
  320. //市--未登录用户不能根据市和地区筛选
  321. city := in.City
  322. if city != "" && isLogin {
  323. if len(query) > 0 {
  324. query += ","
  325. }
  326. query += `{"terms":{"city":[`
  327. for k, v := range strings.Split(city, ",") {
  328. if k > 0 {
  329. query += `,`
  330. }
  331. query += `"` + v + `"`
  332. }
  333. query += `]}}`
  334. }
  335. district := in.District
  336. if district != "" && isLogin {
  337. if len(query) > 0 {
  338. query += ","
  339. }
  340. for k, v := range strings.Split(district, ",") {
  341. if k > 0 {
  342. query += `,`
  343. }
  344. cityName := strings.Split(v, "_")[0]
  345. districtName := strings.Split(v, "_")[1]
  346. queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
  347. query += fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName)
  348. }
  349. }
  350. if query != "" {
  351. query = fmt.Sprintf(QueryBoolShould, query)
  352. }
  353. //发布时间
  354. publishTime := in.PublishTime
  355. if publishTime != "" {
  356. startTime, endTime := "", ""
  357. now := time.Now()
  358. switch publishTime {
  359. case "lately-7":
  360. startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  361. case "lately-30":
  362. startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  363. case "thisyear":
  364. startTime = fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
  365. endTime = fmt.Sprint(now.Unix())
  366. case "threeyear":
  367. startTime = fmt.Sprint(time.Date(now.Year()-3, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
  368. endTime = fmt.Sprint(now.Unix())
  369. case "fiveyear":
  370. startTime = fmt.Sprint(time.Date(now.Year()-5, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
  371. endTime = fmt.Sprint(now.Unix())
  372. default:
  373. if len(strings.Split(publishTime, "-")) > 1 {
  374. startTime = strings.Split(publishTime, "-")[0]
  375. endTime = strings.Split(publishTime, "-")[1]
  376. //电脑端 时间选择 开始时间当天和结束时间当天相同
  377. if startTime == endTime {
  378. et, _ := strconv.ParseInt(endTime, 0, 64)
  379. etTime := time.Unix(et, 0)
  380. endTime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
  381. }
  382. }
  383. }
  384. if startTime != "" || endTime != "" {
  385. if len(query) > 0 {
  386. query += ","
  387. }
  388. query += `{"range":{"publishtime":{`
  389. if startTime != "" {
  390. query += `"gte":` + startTime
  391. }
  392. if startTime != "" && endTime != "" {
  393. query += `,`
  394. }
  395. if endTime != "" {
  396. query += `"lt":` + endTime
  397. }
  398. query += `}}}`
  399. }
  400. }
  401. //信息类型-二级
  402. subtype := in.Subtype
  403. topType := MC.If(in.TopType != "", strings.Split(in.TopType, ","), []string{}).([]string)
  404. allType := ``
  405. //二级分类
  406. if subtype != "" {
  407. var typeInt = 0
  408. allType += `{"terms":{"subtype":[`
  409. for k, v := range strings.Split(subtype, ",") {
  410. if tType := MC.If(topTypeMap[v] != "" && in.TopType == "", topTypeMap[v], "").(string); tType != "" {
  411. topType = append(topType, tType)
  412. typeInt += 1
  413. continue
  414. }
  415. if k > typeInt {
  416. allType += `,`
  417. }
  418. allType += `"` + v + `"`
  419. }
  420. allType += `]}}`
  421. if typeInt == len(strings.Split(subtype, ",")) {
  422. allType = ``
  423. }
  424. }
  425. //信息类型 一级分类
  426. log.Println("topType:", topType)
  427. if len(topType) > 0 {
  428. if allType != "" {
  429. allType += ","
  430. }
  431. allType += `{"terms":{"toptype":[`
  432. for k, v := range topType {
  433. if k > 0 {
  434. allType += `,`
  435. }
  436. allType += `"` + v + `"`
  437. }
  438. allType += `]}}`
  439. }
  440. if allType != "" {
  441. if query != "" {
  442. query += ","
  443. }
  444. query += fmt.Sprintf(QueryBoolShould, allType)
  445. }
  446. //采购单位类型
  447. buyerClass := in.BuyerClass
  448. if buyerClass != "" {
  449. if len(query) > 0 {
  450. query += ","
  451. }
  452. query += `{"terms":{"buyerclass":[`
  453. for k, v := range strings.Split(buyerClass, ",") {
  454. if k > 0 {
  455. query += `,`
  456. }
  457. query += `"` + v + `"`
  458. }
  459. query += `]}}`
  460. }
  461. //电脑端 物业专版BI
  462. if !entity.MobileReg.MatchString(in.UserAgent) {
  463. if in.ExpireTime != "" {
  464. if len(query) > 0 {
  465. query += ","
  466. }
  467. startTime, endTime := "", ""
  468. now := time.Now()
  469. if in.ExpireTime == "1" { //本月到期
  470. startTime = fmt.Sprint(now.Unix())
  471. first := time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, time.Local)
  472. endTime = fmt.Sprint(first.AddDate(0, 0, 0).Unix())
  473. /* endTime = fmt.Sprint(time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, time.Local).Unix())*/
  474. } else if in.ExpireTime == "1-3" { //1-3个月到期
  475. startTime = fmt.Sprint(time.Date(now.Year(), now.Month()+1, now.Day(), 0, 0, 0, 0, time.Local).Unix())
  476. endTime = fmt.Sprint(time.Date(now.Year(), now.Month()+3, now.Day(), 0, 0, 0, 0, time.Local).Unix())
  477. } else if in.ExpireTime == "3-6" { //3-6个月到期
  478. startTime = fmt.Sprint(time.Date(now.Year(), now.Month()+3, now.Day(), 0, 0, 0, 0, time.Local).Unix())
  479. endTime = fmt.Sprint(time.Date(now.Year(), now.Month()+6, now.Day(), 0, 0, 0, 0, time.Local).Unix())
  480. } else if in.ExpireTime == "6-12" { //6-12个月到期
  481. startTime = fmt.Sprint(time.Date(now.Year(), now.Month()+6, now.Day(), 0, 0, 0, 0, time.Local).Unix())
  482. endTime = fmt.Sprint(time.Date(now.Year(), now.Month()+12, now.Day(), 0, 0, 0, 0, time.Local).Unix())
  483. } else if in.ExpireTime == "12" { //12个月以后
  484. startTime = fmt.Sprint(time.Date(now.Year(), now.Month()+12, now.Day(), 0, 0, 0, 0, time.Local).Unix())
  485. } else if len(strings.Split(in.ExpireTime, "_")) > 1 {
  486. startTime = strings.Split(in.ExpireTime, "_")[0]
  487. endTime = strings.Split(in.ExpireTime, "_")[1]
  488. etTime := time.Now()
  489. if endTime != "" {
  490. et, _ := strconv.ParseInt(endTime, 0, 64)
  491. etTime = time.Unix(et, 0)
  492. }
  493. endTime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
  494. }
  495. query += `{"range":{"expiredate":{`
  496. if startTime != "" {
  497. query += `"gte":` + startTime
  498. }
  499. if startTime != "" && endTime != "" {
  500. query += `,`
  501. }
  502. if endTime != "" {
  503. query += `"lt":` + endTime
  504. }
  505. query += `}}}`
  506. }
  507. }
  508. return query
  509. }
  510. // DetailFileORTitle 包含正文或 附件 不包含标题
  511. func DetailFileORTitle(findFields string) bool {
  512. return (strings.Contains(findFields, `"detail"`) || strings.Contains(findFields, `"filetext"`)) && !strings.Contains(findFields, `"title"`)
  513. }