Browse Source

高级搜索

wangchuanjin 8 năm trước cách đây
mục cha
commit
9abae58db9
2 tập tin đã thay đổi với 100 bổ sung26 xóa
  1. 100 25
      src/jfw/front/swordfish.go
  2. 0 1
      src/jfw/timetask/fishindex.go

+ 100 - 25
src/jfw/front/swordfish.go

@@ -29,7 +29,8 @@ const (
 	bidSearch_maxPageSize = 10 //招标搜索分页--最大页数
 	wx_maxPageNum         = 20
 	wx_pageSize           = 50
-	bidSearch_field       = `"_id","title","publishtime","toptype","subtype","type","area","href","detail"`
+	bidSearch_field_1     = `"_id","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","agency","bidamount","budget","biddingcontent"`
+	bidSearch_field       = bidSearch_field_1 + `,"detail"`
 	bidSearch_sort        = `{"publishtime":-1}`
 )
 
@@ -137,8 +138,9 @@ func (m *Front) NewSordfish() error {
 			return m.SetBody([]byte(ret.(string)))
 		} else {
 			m.DisableHttpCache()
-			lastBids := elastic.GetPage("bidding", "bidding", "{}", `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href"`, 0, 18)
+			lastBids := elastic.GetPage("bidding", "bidding", "{}", bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","biddingcontent"`, 0, 18)
 			if lastBids != nil && len(*lastBids) > 0 {
+				bidListConvert("", lastBids)
 				lbnHtml, olHtml := structureLastBidsHtml(lastBids)
 				m.T["lbnHtml"] = lbnHtml
 				m.T["olHtml"] = olHtml
@@ -279,6 +281,7 @@ func (m *Front) Searchinfolist(p string) error {
 	publishtime := m.GetString("publishtime")
 	toptype := m.GetString("toptype")
 	subtype := m.GetString("subtype")
+	industry := m.GetString("industry")
 	selectType := m.GetString("selectType")
 	selectTypesess := m.GetSession("selectType")
 	if selectTypesess != nil && selectTypesess != "" {
@@ -292,10 +295,10 @@ func (m *Front) Searchinfolist(p string) error {
 	var list *[]map[string]interface{}
 	pages := make([]interface{}, 0)
 	if len(searchvalue) > 0 {
-		count, list = getBidSearchData(searchvalue, area, publishtime, subtype, 0, true, selectType)
+		count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, 0, true, selectType)
 	} else if m.Method() == "POST" {
 		status = 2
-		count, list = getLastNewsData(searchvalue, area, publishtime, subtype, 0, true)
+		count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, 0, true)
 	} else {
 		status = 2
 		if redis.Get("other", "index_list") == nil {
@@ -314,7 +317,7 @@ func (m *Front) Searchinfolist(p string) error {
 				}
 			}
 			for i := 0; i < 10; i++ {
-				count, list = getLastNewsData(searchvalue, area, publishtime, subtype, intns[i], true)
+				count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, intns[i], true)
 				for k, v := range *list {
 					v["k"] = (k + 1) + i*50
 					t := time.Unix(util.Int64All(v["publishtime"]), 0)
@@ -418,8 +421,10 @@ func (m *Front) PcAjaxReq() {
 	reqType := m.GetString("reqType")
 	//获取最新招标信息
 	if reqType == "lastBids" {
+		ls := elastic.GetPage(INDEX, TYPE, "{}", bidSearch_sort, bidSearch_field_1, 0, 18)
+		bidListConvert("", ls)
 		m.ServeJson(map[string]interface{}{
-			"list": elastic.GetPage("bidding", "bidding", "{}", `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href"`, 0, 18),
+			"list": ls,
 		})
 		return
 	} else if reqType == "rewardText" {
@@ -437,6 +442,7 @@ func (m *Front) PcAjaxReq() {
 	searchvalue := m.GetString("searchvalue")
 	publishtime := m.GetString("publishtime")
 	selectType := m.GetString("selectType")
+	industry := m.GetString("industry")
 	m.SetSession("selectType", selectType)
 	fmt.Println(selectType)
 
@@ -445,14 +451,14 @@ func (m *Front) PcAjaxReq() {
 	status, _ := m.GetInteger("status")
 	if reqType == "filter" {
 		if status == 1 {
-			count, list = getBidSearchData(searchvalue, area, publishtime, subtype, 0, true, selectType)
+			count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, 0, true, selectType)
 		} else if status == 2 {
-			count, list = getLastNewsData(searchvalue, area, publishtime, subtype, 0, true)
+			count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, 0, true)
 		}
 	} else if reqType == "bidSearch" {
-		_, list = getBidSearchData(searchvalue, area, publishtime, subtype, start, false, selectType)
+		_, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, start, false, selectType)
 	} else if reqType == "lastNews" {
-		_, list = getLastNewsData(searchvalue, area, publishtime, subtype, start, false)
+		_, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, start, false)
 	}
 	if list != nil && len(*list) > 0 {
 		for _, v := range *list {
@@ -484,8 +490,8 @@ func (m *Front) PcAjaxReq() {
 /**
 **页面搜索
 **/
-func getBidSearchData(searchvalue, area, publishtime, subtype string, start int, isGetCount bool, selectType string) (count int64, list *[]map[string]interface{}) {
-	query := getBidSearchQuery(area, publishtime, subtype)
+func getBidSearchData(searchvalue, area, publishtime, subtype, industry string, start int, isGetCount bool, selectType string) (count int64, list *[]map[string]interface{}) {
+	query := getBidSearchQuery(area, publishtime, subtype, industry)
 	//selectType:全文搜索(all)、标题搜索(title)
 	var qstr string
 	qstr = elastic.GetNgramQuery(searchvalue, query, `"title","detail"` /*FINDF*/)
@@ -502,6 +508,7 @@ func getBidSearchData(searchvalue, area, publishtime, subtype string, start int,
 			repl = elastic.GetByNgram(INDEX, TYPE, searchvalue, query, `"title"` /*FINDF*/, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize)
 		}
 		if repl != nil && *repl != nil && len(*repl) > 0 {
+			bidListConvert(industry, repl)
 			list = repl
 		}
 	}
@@ -511,9 +518,9 @@ func getBidSearchData(searchvalue, area, publishtime, subtype string, start int,
 	}
 	return
 }
-func getLastNewsData(searchvalue, area, publishtime, subtype string, start int, isGetCount bool) (count int64, list *[]map[string]interface{}) {
+func getLastNewsData(searchvalue, area, publishtime, subtype, industry string, start int, isGetCount bool) (count int64, list *[]map[string]interface{}) {
 	//最新招标信息
-	query := getBidSearchQuery(area, publishtime, subtype)
+	query := getBidSearchQuery(area, publishtime, subtype, industry)
 	strquery := `{"query":{"bool":{"must":[` + query + `],"must_not":[],"should":[],"minimum_should_match" : 1}}}`
 	if isGetCount {
 		count = elastic.Count(INDEX, TYPE, strquery)
@@ -526,6 +533,7 @@ func getLastNewsData(searchvalue, area, publishtime, subtype string, start int,
 		}
 		repl := elastic.GetByNgramOther(INDEX, TYPE, searchvalue, query, `"title","detail"` /*FINDF*/, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, true, false, 115)
 		if repl != nil && *repl != nil && len(*repl) > 0 {
+			bidListConvert(industry, repl)
 			list = repl
 		}
 	}
@@ -535,7 +543,7 @@ func getLastNewsData(searchvalue, area, publishtime, subtype string, start int,
 	}
 	return
 }
-func getBidSearchQuery(area, publishtime, subtype string) string {
+func getBidSearchQuery(area, publishtime, subtype, industry string) string {
 	query := ``
 	if area != "" {
 		query += `{"terms":{"area":[`
@@ -595,6 +603,19 @@ func getBidSearchQuery(area, publishtime, subtype string) string {
 		}
 		query += `]}}`
 	}
+	if industry != "" {
+		if len(query) > 0 {
+			query += ","
+		}
+		query += `{"regexp":{"industry":".*(`
+		for k, v := range strings.Split(industry, ",") {
+			if k > 0 {
+				query += `|`
+			}
+			query += "," + v + ","
+		}
+		query += `).*"}}`
+	}
 	return query
 }
 func getLastNewsQuery(area, publishtime, subtype string) string {
@@ -698,6 +719,7 @@ func (m *Front) Wxsearch() error {
 	subtype := m.GetSession("subtype")
 	scope := m.GetSession("scope")
 	publishtime := m.GetSession("publishtime")
+	industry := m.GetSession("industry")
 	if shname != "" && shname != nil {
 		m.T["shname"] = shname
 	}
@@ -705,6 +727,7 @@ func (m *Front) Wxsearch() error {
 	m.T["subtype"] = subtype
 	m.T["scope"] = scope
 	m.T["publishtime"] = publishtime
+	m.T["industry"] = industry
 	m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
 	mynickname, _ := m.Session().Get("s_nickname").(string)
 	myavatar, _ := m.Session().Get("s_avatar").(string)
@@ -748,12 +771,14 @@ func (m *Front) Wxsearchlist() error {
 	searchvalue := m.GetString("searchvalue")
 	toptype := m.GetString("toptype")
 	subtype := m.GetString("subtype")
+	industry := m.GetString("industry")
 	scope := m.GetString("scope")
 	publishtime := m.GetString("publishtime")
 	selectType := m.GetString("selectType")
 	m.SetSession("shname", keywords)
 	m.SetSession("toptype", toptype)
 	m.SetSession("subtype", subtype)
+	m.SetSession("industry", industry)
 	m.SetSession("scope", scope)
 	m.SetSession("publishtime", publishtime)
 	var list *[]map[string]interface{}
@@ -762,7 +787,7 @@ func (m *Front) Wxsearchlist() error {
 			if selectType == "" { //默认设置为全文搜索
 				selectType = "all"
 			}
-			list = getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, 1, selectType)
+			list = getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry, 1, selectType)
 
 			r := redis.GetStr("other", "s_"+userid.(string))
 			arrs := strings.Split(r, ",")
@@ -818,7 +843,8 @@ func (m *Front) WxsearchlistPaging() {
 		scope := m.GetString("scope")
 		publishtime := m.GetString("publishtime")
 		selectType := m.GetString("selectType")
-		list = getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, pageNum, selectType)
+		industry := m.GetString("industry")
+		list = getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry, pageNum, selectType)
 	}
 	m.ServeJson(map[string]interface{}{
 		"list":        list,
@@ -842,18 +868,17 @@ func (m *Front) DelWxHistorySearch() {
 }
 
 //微信端搜索
-func getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype string, pageNum int, selectType string) (list *[]map[string]interface{}) {
-	field := `"_id","title","publishtime","toptype","subtype","type","area","href"`
-	sort := `{"publishtime":-1}`
-	query := getBidSearchQuery(scope, publishtime, subtype) //scope是地区对应传进的areas, stype是类型对应scope
+func getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry string, pageNum int, selectType string) (list *[]map[string]interface{}) {
+	query := getBidSearchQuery(scope, publishtime, subtype, industry) //scope是地区对应传进的areas, stype是类型对应scope
 	if len(keywords) > 0 {
 		if selectType == "all" { //全文搜索
-			list = elastic.GetByNgramOther(INDEX, TYPE, searchvalue, query, `"title","detail"`, sort, field, (pageNum-1)*wx_pageSize, wx_pageSize, true, false, 100)
+			list = elastic.GetByNgramOther(INDEX, TYPE, searchvalue, query, `"title","detail"`, bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize, true, false, 100)
 		} else { //标题搜索
-			list = elastic.GetByNgram(INDEX, TYPE, searchvalue, query, `"title"` /*FINDF*/, sort, field, (pageNum-1)*wx_pageSize, wx_pageSize)
+			list = elastic.GetByNgram(INDEX, TYPE, searchvalue, query, `"title"` /*FINDF*/, bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize)
 		}
 
 		if list != nil {
+			bidListConvert("", list)
 			for _, v := range *list {
 				v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
 			}
@@ -1060,7 +1085,7 @@ func pcVRT(sid string) (po, bo, wo []map[string]interface{}, objdata map[string]
 			objdata = *obj
 			queryStr := ""
 			commonQuery := func(mustquery string) *[]map[string]interface{} {
-				return elastic.GetPage("bidding", "bidding", queryStr, `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href"`, 0, 11)
+				return elastic.GetPage("bidding", "bidding", queryStr, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href"`, 0, 11)
 			}
 			//同一个项目的其他招标信息
 			projectName, _ := (*obj)["projectname"].(string)
@@ -1960,7 +1985,7 @@ func (f *Front) SearchResult(at, name string) error {
 			if count1 < startPage || startPage < 0 {
 				startPage = 0
 			}
-			datas = elastic.GetPage(INDEX, TYPE, query, `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href"`, startPage, limitcount)
+			datas = elastic.GetPage(INDEX, TYPE, query, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href"`, startPage, limitcount)
 			redis.Put("other", "classify_"+name, datas, 2*60*60)
 		} else {
 			b, _ := json.Marshal(list)
@@ -2101,3 +2126,53 @@ func (m *Front) Subscribe() error {
 	m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
 	return m.Render("/pc/subscribe.html", &m.T)
 }
+
+/*
+ * 结果列表转换,目前只换行行业字段
+ * 所有的招标搜索都要调用此方法,列表中有展示行业的也可以用
+ * industry 搜索条件中的行业,默认为空
+ */
+func bidListConvert(industry string, list *[]map[string]interface{}) {
+	if list == nil {
+		return
+	}
+	commonSubstring := func(v string) (value string) {
+		bcs := strings.Split(v, "_")
+		if len(bcs) == 1 {
+			value = bcs[0]
+		} else if len(bcs) == 2 {
+			value = bcs[1]
+			if strings.TrimSpace(value) == "" {
+				value = bcs[0]
+			}
+		}
+		return
+	}
+	for _, v := range *list {
+		value := ""
+		biddingcontent, _ := v["biddingcontent"].([]interface{})
+		bct := util.ObjArrToStringArr(biddingcontent)
+		if bct == nil || len(bct) == 0 {
+			continue
+		}
+		//搜索条件中没有行业的话,取查询结果中第一个行业
+		if industry == "" {
+			value = commonSubstring(bct[0])
+		} else { //搜索条件中有行业的话,取行业中和搜索条件相对应的第一个
+			industrys := strings.Split(industry, ",")
+		L:
+			for _, bc := range bct {
+				for _, is := range industrys {
+					if bc == is {
+						value = commonSubstring(bc)
+						break L
+					}
+				}
+			}
+		}
+		if strings.TrimSpace(value) == "" {
+			continue
+		}
+		v["industry"] = value
+	}
+}

+ 0 - 1
src/jfw/timetask/fishindex.go

@@ -138,7 +138,6 @@ func othershow() error {
 		sess := mongodb.GetMgoConn()
 		defer mongodb.DestoryMongoConn(sess)
 		var res bson.M
-		log.Println(lastTime)
 		pusherr := sess.DB("qfw").C("wxpush").Pipe([]bson.M{bson.M{"$match": bson.M{"l_date": bson.M{"$gte": lastTime}}},
 			bson.M{"$group": bson.M{"_id": "sum", "totalAmount": bson.M{"$sum": "$i_size"}}}}).One(&res)
 		if pusherr != nil {