瀏覽代碼

fix:代码优化整合

duxin 3 年之前
父節點
當前提交
d59de61d69

+ 2 - 2
src/jfw/front/supsearch.go

@@ -258,7 +258,7 @@ func (p *Pcsearch) PcSearchIndex() error {
 	if selectType == "" {
 		selectType = "title,content"
 	}
-	isPayedUser, publishtime, queryItems, _, _ := bidsearch.PublicSearch(userId, selectType, publishtime, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"]), 2, 0)
+	isPayedUser, publishtime, queryItems, _, _ := bidsearch.PublicSearch(userId, selectType, publishtime, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"]), 0)
 	if isPayedUser {
 		buyerclass = p.GetString("buyerclass")
 		hasBuyerTel, hasWinnerTel = p.GetString("buyertel"), p.GetString("winnertel")
@@ -299,7 +299,7 @@ func (p *Pcsearch) PcSearchIndex() error {
 		count, totalPage = 500, 10
 	}
 	if status == 2 {
-		secondList, tp := bidsearch.LisetData(1, list, secondFlag, config.Sysconfig)
+		secondList, tp, _ := bidsearch.LisetData(1, 0, list, secondFlag, config.Sysconfig, isPayedUser)
 		if tp == 1 {
 			p.T["secondList"] = ""
 			totalPage = 1

+ 9 - 79
src/jfw/front/swordfish.go

@@ -114,7 +114,7 @@ func (m *Front) PcAjaxReq() {
 		queryItems                []string
 		start                     int
 	)
-	isPayedUser, publishtime, queryItems, currentPage, start = bidsearch.PublicSearch(userId, selectType, publishtime, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"]), 2, currentPage)
+	isPayedUser, publishtime, queryItems, currentPage, start = bidsearch.PublicSearch(userId, selectType, publishtime, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"]), currentPage)
 	if isPayedUser {
 		buyerclass = m.GetString("buyerclass")
 		hasBuyerTel, hasWinnerTel = m.GetString("buyertel"), m.GetString("winnertel")
@@ -152,9 +152,8 @@ func (m *Front) PcAjaxReq() {
 		if isLimit == 1 {
 			_, _, _, pcAjaxFlag, secondFlag, count, totalPage, list = bidsearch.SearchData(1, m.Request, currentPage, util.ObjToString(m.GetSession("userId")), secondKWS, s_word, area, publishtime, subtype, industry, minprice, maxprice, "", buyerclass, hasBuyerTel, hasWinnerTel, start, bidsearch.SearchPageSize_PC, true, queryItems, field, notkey, isPayedUser)
 		}
-
 	}
-	secondList, totalPage = bidsearch.LisetData(1, list, secondFlag, config.Sysconfig) //只有前20条
+	secondList, totalPage, _ = bidsearch.LisetData(1, currentPage, list, secondFlag, config.Sysconfig, isPayedUser) //只有前20条
 	m.ServeJson(map[string]interface{}{
 		"limitFlag":     false,
 		"status":        isLimit,
@@ -309,14 +308,14 @@ func (m *Front) WxsearchlistPaging() {
 	defer util.Catch()
 	userId, _ := m.GetSession("userId").(string)
 	var list *[]map[string]interface{}
-	var secRel *[]map[string]interface{}
-	var b_word, a_word, s_word, secondFlag, secondKWS string
+	var b_word, a_word, secondFlag, secondKWS string
 	var secondList []map[string]interface{}
 	var limitFlag, hasNextPage bool
 	isLimit := 1
 	pageNum, _ := m.GetInteger("pageNum")
 	var keys []interface{}
 	var arrs []string
+	var isPayedUser bool
 	func() {
 		if userId == "" {
 			return
@@ -326,8 +325,7 @@ func (m *Front) WxsearchlistPaging() {
 		history := redis.GetStr("other", "s_"+userId)
 		arrs = strings.Split(history, ",")
 		searchvalue := strings.TrimSpace(m.GetString("searchvalue"))
-		isPayedUser := false
-		var secondList []map[string]interface{}
+
 		if searchvalue != "" {
 			filed := bidSearch_field_1
 			if pageNum == 1 {
@@ -377,82 +375,12 @@ func (m *Front) WxsearchlistPaging() {
 				}
 			}
 			if isLimit == 1 {
-				list, b_word, a_word, s_word = bidsearch.GetWxsearchlistData(searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, "", buyerclass, hasBuyerTel, hasWinnerTel, pageNum, bidsearch.SearchPageSize_WX, queryItems, filed, notkey)
-				listSize := 0
-				if list != nil {
-					listSize = len(*list)
-				}
-				if len([]rune(s_word)) > 3 && listSize < bidsearch.SearchPageSize_WX && pageNum == 1 {
-					secondSearch := false
-					for _, item := range queryItems {
-						if item == "title" {
-							secondSearch = true
-							break
-						}
-					}
-					if secondSearch {
-						secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
-						findfields := `"title"`
-						qstr := getSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, bidsearch.GetBidSearchQuery(scope, publishtime, subtype, "", buyerclass))
-						secRel = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, filed, 0, 2*bidsearch.SearchPageSize_WX, 0, false)
-						if secRel != nil && len(*secRel) > 0 {
-							public.BidListConvert(industry, secRel)
-							for _, v := range *secRel {
-								v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
-							}
-							if list != nil {
-								list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
-							} else {
-								list = secRel
-							}
-							secondFlag = "T"
-							if len(*list) > bidsearch.SearchPageSize_WX && selectType == "title" {
-								secondList = (*list)[bidsearch.SearchPageSize_WX:]
-								if len(secondList) > bidsearch.SearchPageSize_WX {
-									secondList = secondList[:bidsearch.SearchPageSize_WX]
-								}
-								*list = (*list)[:bidsearch.SearchPageSize_WX]
-							}
-						} else {
-							secondKWS = ""
-						}
-					}
-				}
-				public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "wx", "超级搜索", map[string]interface{}{
-					"search_word":        searchvalue,
-					"search_area":        scope,
-					"search_price":       []string{minprice, maxprice},
-					"search_publishtime": publishtime,
-					"search_type":        subtype,
-					"search_industry":    industry,
-					"pagenum":            pageNum,
-					"pagesize":           listSize,
-				})
+				secondKWS, b_word, a_word, _, secondFlag, _, _, list = bidsearch.SearchData(4, m.Request, pageNum, util.ObjToString(m.GetSession("userId")), secondKWS, searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, "", buyerclass, hasBuyerTel, hasWinnerTel, pageNum, bidsearch.SearchPageSize_APP, true, queryItems, filed, notkey, isPayedUser)
 			}
 			//新增历史记录
-			if history == "" {
-				arrs = make([]string, 0)
-			}
-			for k, v := range arrs {
-				if v == strings.Trim(searchvalue, " ") {
-					arrs = append(arrs[:k], arrs[k+1:]...)
-					break
-				}
-			}
-			arrs = append(arrs, searchvalue)
-			if len(arrs) > 10 {
-				arrs = arrs[1:11]
-			}
+			arrs = bidsearch.AddHistory(history, searchvalue)
 			redis.Del("other", "s_"+userId)
 			redis.Put("other", "s_"+userId, strings.Join(arrs, ","), -1)
-			if list != nil && len(*list) == bidsearch.SearchPageSize_WX {
-				hasNextPage = true
-			}
-			if isPayedUser && pageNum >= bidsearch.SearchMaxPageNum_PAYED {
-				hasNextPage = false
-			} else if !isPayedUser && pageNum >= bidsearch.SearchMaxPageNum_WX {
-				hasNextPage = false
-			}
 		}
 		if one != nil && len(*one) > 0 {
 			o_jy, _ := (*one)["o_jy"].(map[string]interface{})
@@ -464,6 +392,8 @@ func (m *Front) WxsearchlistPaging() {
 			}
 		}
 	}()
+	//同app  避免二次加密
+	secondList, _, hasNextPage = bidsearch.LisetData(4, pageNum, list, secondFlag, config.Sysconfig, isPayedUser)
 	m.ServeJson(map[string]interface{}{
 		"limitFlag":     limitFlag,
 		"status":        isLimit,

+ 9 - 21
src/jfw/modules/app/src/app/front/swordfish.go

@@ -227,21 +227,7 @@ func (m *Front) WxsearchlistPaging() {
 	if userid != "" {
 		//历史记录
 		history := redis.GetStr("other", "s_"+userid)
-		arrs := strings.Split(history, ",")
-		//新增历史记录
-		if history == "" {
-			arrs = make([]string, 0)
-		}
-		for k, v := range arrs {
-			if v == strings.TrimSpace(searchvalue) {
-				arrs = append(arrs[:k], arrs[k+1:]...)
-				break
-			}
-		}
-		arrs = append(arrs, searchvalue)
-		if len(arrs) > 10 {
-			arrs = arrs[1:11]
-		}
+		arrs := bidsearch.AddHistory(history, searchvalue)
 		redis.Del("other", "s_"+userid)
 		redis.Put("other", "s_"+userid, strings.Join(arrs, ","), -1)
 		m.T["history"] = arrs
@@ -254,6 +240,7 @@ func (m *Front) WxsearchlistPaging() {
 		secondFlag     = ""
 		queryItems     []string
 		isPayedUser    bool
+		hasNextPage    bool
 		secondList     []map[string]interface{}
 	)
 
@@ -271,7 +258,7 @@ func (m *Front) WxsearchlistPaging() {
 		buyerclass := ""                              //采购单位类别
 		var notkey string = ""                        //排除词
 
-		isPayedUser, publishtime, queryItems, pageNum, _ = bidsearch.PublicSearch(userid, selectType, publishtime, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"]), 2, pageNum)
+		isPayedUser, publishtime, queryItems, pageNum, _ = bidsearch.PublicSearch(userid, selectType, publishtime, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"]), pageNum)
 		if isPayedUser {
 			buyerclass = m.GetString("buyerclass")
 			hasBuyerTel, hasWinnerTel = m.GetString("buyertel"), m.GetString("winnertel")
@@ -291,20 +278,21 @@ func (m *Front) WxsearchlistPaging() {
 			}
 		}
 		//第一页数据展示多字段(table表格需要)
-		feld := bidSearch_field_1
+		filed := bidSearch_field_1
 		if pageNum == 1 {
-			feld = bidSearch_field
+			filed = bidSearch_field
 		}
 		if isLimit == 1 {
-			secondKWS, b_word, a_word, _, secondFlag, _, _, list = bidsearch.SearchData(3, m.Request, pageNum, util.ObjToString(m.GetSession("userId")), secondKWS, searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, pageNum, bidsearch.SearchPageSize_APP, true, queryItems, feld, notkey, isPayedUser)
+			secondKWS, b_word, a_word, _, secondFlag, _, _, list = bidsearch.SearchData(3, m.Request, pageNum, util.ObjToString(m.GetSession("userId")), secondKWS, searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, pageNum, bidsearch.SearchPageSize_APP, true, queryItems, filed, notkey, isPayedUser)
 		}
 	}
-	secondList, _ = bidsearch.LisetData(3, list, secondFlag, config.Sysconfig)
+
+	secondList, _, hasNextPage = bidsearch.LisetData(3, pageNum, list, secondFlag, config.Sysconfig, isPayedUser)
 	m.ServeJson(map[string]interface{}{
 		"limitFlag":     false,
 		"status":        isLimit,
 		"list":          list,
-		"hasNextPage":   list != nil && len(*list) == bidsearch.SearchPageSize_APP && pageNum < util.If(isPayedUser, bidsearch.SearchMaxPageNum_PAYED, bidsearch.SearchMaxPageNum_APP).(int),
+		"hasNextPage":   hasNextPage,
 		"history":       m.T["history"],
 		"msgset":        m.T["msgset"],
 		"interceptWord": a_word,

+ 55 - 29
src/jfw/modules/common/src/qfw/util/bidsearch/search.go

@@ -282,25 +282,20 @@ func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinne
 	return
 }
 
-func PublicSearch(userId, selectType, publishtime string, bidSearchOldUserLimit, stype int64, currentPage int) (bool, string, []string, int, int) {
+func PublicSearch(userId, selectType, publishtime string, bidSearchOldUserLimit int64, currentPage int) (bool, string, []string, int, int) {
 	var start int
 	vipStatus := jy.GetVipState(public.Mysql, public.MQFW, userId)
 	isPayedUser := vipStatus.IsPayedUser()
 	queryItems := vipStatus.GetQueryItems(selectType, bidSearchOldUserLimit)
 
 	if isPayedUser {
-		if stype == 1 || stype == 3 {
-			if currentPage > SearchMaxPageNum_PAYED {
-				currentPage = SearchMaxPageNum_PAYED
-			}
+		if currentPage > SearchMaxPageNum_PAYED {
+			currentPage = SearchMaxPageNum_PAYED
 		}
 	} else {
-		if stype == 1 || stype == 3 {
-			if currentPage > SearchMaxPageNum_PC {
-				currentPage = SearchMaxPageNum_PC
-			}
+		if currentPage > SearchMaxPageNum_PC {
+			currentPage = SearchMaxPageNum_PC
 		}
-
 		//时间自定义选择默认是vip 大会员 等权限
 		if len(strings.Split(publishtime, "_")) == 2 {
 			publishtime = ""
@@ -326,9 +321,9 @@ func IntegratedData(stype int, s_word, secondKWS, industry, minprice, maxprice,
 		findfields := `"title"`
 		qstr := GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, GetBidSearchQuery(area, publishtime, subtype, "", buyerclass), notkey)
 		secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, 2*SearchPageSize_PC, 0, false)
-		if secRel != nil {
+		if secRel != nil && len(*secRel) > 0 {
 			public.BidListConvert(industry, secRel)
-			if stype == 3 {
+			if stype == 3 || stype == 4 {
 				for _, v := range *secRel {
 					v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
 				}
@@ -339,14 +334,11 @@ func IntegratedData(stype int, s_word, secondKWS, industry, minprice, maxprice,
 		} else {
 			list = secRel
 		}
-		if len(*secRel) > 0 {
-			if secondKWS != "" {
-				s_word += "+" + secondKWS
-			}
-			secondFlag = "T"
-			pcAjaxFlag = "T"
+		secondFlag = "T"
+		pcAjaxFlag = "T"
+		if secondKWS != "" {
+			s_word += "+" + secondKWS
 		}
-
 	}
 	return s_word, pcAjaxFlag, secondFlag, secondKWS
 }
@@ -384,15 +376,17 @@ func classify(stp, area, industry string, configData map[string]interface{}) (st
 	return tpadd, areaadd, induadd
 }
 
+//list != nil && len(*list) == bidsearch.SearchPageSize_APP && pageNum < util.If(isPayedUser, bidsearch.SearchMaxPageNum_PAYED, bidsearch.SearchMaxPageNum_APP).(int)
 //数据格式化处理
-func LisetData(stype int, list *[]map[string]interface{}, secondFlag string, configData map[string]interface{}) ([]map[string]interface{}, int64) {
+func LisetData(stype, pageNum int, list *[]map[string]interface{}, secondFlag string, configData map[string]interface{}, isPayedUser bool) ([]map[string]interface{}, int64, bool) {
 	var (
-		secondList []map[string]interface{}
-		totalPage  int64
+		secondList  []map[string]interface{}
+		totalPage   int64
+		hasNextPage bool
 	)
 	if list != nil && len(*list) > 0 {
-		for _, v := range *list {
-			if stype != 3 {
+		if stype != 3 && stype != 4 {
+			for _, v := range *list {
 				if v["_id"] != nil {
 					v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
 				}
@@ -426,17 +420,30 @@ func LisetData(stype int, list *[]map[string]interface{}, secondFlag string, con
 			}
 		}
 	}
-	return secondList, totalPage
+
+	if list != nil && len(*list) == SearchPageSize_WX {
+		hasNextPage = true
+	}
+	if isPayedUser && pageNum >= SearchMaxPageNum_PAYED {
+		hasNextPage = false
+	} else if !isPayedUser && pageNum >= SearchMaxPageNum_WX {
+		hasNextPage = false
+	}
+	return secondList, totalPage, hasNextPage
 }
 
+//1 2 pc 3 app 4 wx
 func SearchData(stype int, request *http.Request, currentPage int, userId, secondKWS, s_word, area, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel string, start, pageSize int, isGetCount bool, queryItems []string, field, notkey string, isPayedUser bool) (second, b_word, a_word, pcAjaxFlag, secondFlag string, count, totalPage int64, list *[]map[string]interface{}) {
 	var (
-		platform string
-		number   int
+		platform    string
+		searchvalue = s_word
 	)
+	number := util.If(stype == 3 || stype == 4, 1, 0)
 	if stype == 3 {
 		platform = "app"
-		number = 1
+		list, b_word, a_word, s_word = GetWxsearchlistData(s_word, area, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, start, SearchPageSize_APP, queryItems, field, notkey)
+	} else if stype == 4 {
+		platform = "wx"
 		list, b_word, a_word, s_word = GetWxsearchlistData(s_word, area, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, start, SearchPageSize_APP, queryItems, field, notkey)
 	} else {
 		platform = "pc"
@@ -451,7 +458,7 @@ func SearchData(stype int, request *http.Request, currentPage int, userId, secon
 		s_word, pcAjaxFlag, secondFlag, second = IntegratedData(stype, s_word, secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, secondFlag, area, publishtime, subtype, buyerclass, notkey, queryItems, list)
 	}
 	public.SaveUserSearchLog(request, userId, -1, platform, "超级搜索", map[string]interface{}{
-		"search_word":        s_word,
+		"search_word":        util.If(stype == 3 || stype == 4, searchvalue, s_word),
 		"search_area":        area,
 		"search_price":       []string{minprice, maxprice},
 		"search_publishtime": publishtime,
@@ -462,3 +469,22 @@ func SearchData(stype int, request *http.Request, currentPage int, userId, secon
 	})
 	return
 }
+
+func AddHistory(history, searchvalue string) []string {
+	arrs := strings.Split(history, ",")
+	//新增历史记录
+	if history == "" {
+		arrs = make([]string, 0)
+	}
+	for k, v := range arrs {
+		if v == strings.TrimSpace(searchvalue) {
+			arrs = append(arrs[:k], arrs[k+1:]...)
+			break
+		}
+	}
+	arrs = append(arrs, searchvalue)
+	if len(arrs) > 10 {
+		arrs = arrs[1:11]
+	}
+	return arrs
+}