Kaynağa Gözat

查询数量不够时,二次查询修改

wangkaiyue 4 yıl önce
ebeveyn
işleme
4516b3e5f9

+ 24 - 15
src/jfw/front/supsearch.go

@@ -296,23 +296,32 @@ func (p *Pcsearch) PcSearchIndex() error {
 		}
 		//所有的再次分词查询 只查标题
 		if len([]rune(s_word)) > 3 && int(count) < bidsearch.SearchPageSize_PC {
-			secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
-			findfields := `"title"`
-			qstr := bidsearch.GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, bidsearch.GetBidSearchQuery(area, publishtime, subtype, "", buyerclass))
-			secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, 2*bidsearch.SearchPageSize_PC, 0, false)
-			if secRel != nil {
-				public.BidListConvert(industry, secRel)
-			}
-			if list != nil {
-				list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
-			} else {
-				list = secRel
+			secondSearch := false
+			for _, item := range queryItems {
+				if item == "title" {
+					secondSearch = true
+					break
+				}
 			}
-			if len(*secRel) > 0 {
-				if secondKWS != "" {
-					s_word += "+" + secondKWS
+			if secondSearch {
+				secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
+				findfields := `"title"`
+				qstr := bidsearch.GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, bidsearch.GetBidSearchQuery(area, publishtime, subtype, "", buyerclass))
+				secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, 2*bidsearch.SearchPageSize_PC, 0, false)
+				if secRel != nil {
+					public.BidListConvert(industry, secRel)
+				}
+				if list != nil {
+					list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
+				} else {
+					list = secRel
+				}
+				if len(*secRel) > 0 {
+					if secondKWS != "" {
+						s_word += "+" + secondKWS
+					}
+					secondFlag = "T"
 				}
-				secondFlag = "T"
 			}
 		}
 		//		s_word = strings.Replace(s_word, "+", " ", -1)

+ 55 - 37
src/jfw/front/swordfish.go

@@ -189,24 +189,33 @@ func (m *Front) PcAjaxReq() {
 					listSize = len(*list)
 				}
 				if len([]rune(s_word)) > 3 && int(count) < bidsearch.SearchPageSize_PC && start == 0 {
-					secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
-					findfields := `"title"`
-					qstr := bidsearch.GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, bidsearch.GetBidSearchQuery(area, publishtime, subtype, "", buyerclass))
-					secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, 2*bidsearch.SearchPageSize_PC, 0, false)
-					if secRel != nil {
-						public.BidListConvert(industry, secRel)
-					}
-					if list != nil {
-						list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
-					} else {
-						list = secRel
+					secondSearch := false
+					for _, item := range queryItems {
+						if item == "title" {
+							secondSearch = true
+							break
+						}
 					}
-					if len(*secRel) > 0 {
-						if secondKWS != "" {
-							s_word += "+" + secondKWS
+					if secondSearch {
+						secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
+						findfields := `"title"`
+						qstr := bidsearch.GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, bidsearch.GetBidSearchQuery(area, publishtime, subtype, "", buyerclass))
+						secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, 2*bidsearch.SearchPageSize_PC, 0, false)
+						if secRel != nil {
+							public.BidListConvert(industry, secRel)
+						}
+						if list != nil {
+							list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
+						} else {
+							list = secRel
+						}
+						if len(*secRel) > 0 {
+							if secondKWS != "" {
+								s_word += "+" + secondKWS
+							}
+							secondFlag = "T"
+							pcAjaxFlag = "T"
 						}
-						secondFlag = "T"
-						pcAjaxFlag = "T"
 					}
 				}
 				public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "pc", "超级搜索", map[string]interface{}{
@@ -482,30 +491,39 @@ func (m *Front) WxsearchlistPaging() {
 					listSize = len(*list)
 				}
 				if len([]rune(s_word)) > 3 && listSize < bidsearch.SearchPageSize_WX && pageNum == 1 {
-					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"]))
+					secondSearch := false
+					for _, item := range queryItems {
+						if item == "title" {
+							secondSearch = true
+							break
 						}
-						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]
+					}
+					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]
 							}
-							*list = (*list)[:bidsearch.SearchPageSize_WX]
+						} else {
+							secondKWS = ""
 						}
-					} else {
-						secondKWS = ""
 					}
 				}
 				public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "wx", "超级搜索", map[string]interface{}{

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

@@ -318,30 +318,39 @@ func (m *Front) WxsearchlistPaging() {
 					listSize = len(*list)
 				}
 				if len([]rune(s_word)) > 3 && listSize < bidsearch.SearchPageSize_APP && pageNum == 1 {
-					secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
-					findfields := `"title"`
-					qstr := bidsearch.GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, bidsearch.GetBidSearchQuery(scope, publishtime, subtype, winner, buyerclass))
-					secRel = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, feld, 0, 2*bidsearch.SearchPageSize_APP, 0, false)
-					if secRel != nil && len(*secRel) > 0 {
-						public.BidListConvert(industry, secRel)
-						for _, v := range *secRel {
-							v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
+					secondSearch := false
+					for _, item := range queryItems {
+						if item == "title" {
+							secondSearch = true
+							break
 						}
-						if list != nil {
-							list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
-						} else {
-							list = secRel
-						}
-						secondFlag = "T"
-						if len(*list) > bidsearch.SearchPageSize_APP && selectType == "title" {
-							secondList = (*list)[bidsearch.SearchPageSize_APP:]
-							if len(secondList) > bidsearch.SearchPageSize_APP {
-								secondList = secondList[:bidsearch.SearchPageSize_APP]
+					}
+					if secondSearch {
+						secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
+						findfields := `"title"`
+						qstr := bidsearch.GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, bidsearch.GetBidSearchQuery(scope, publishtime, subtype, winner, buyerclass))
+						secRel = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, feld, 0, 2*bidsearch.SearchPageSize_APP, 0, false)
+						if secRel != nil && len(*secRel) > 0 {
+							public.BidListConvert(industry, secRel)
+							for _, v := range *secRel {
+								v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
 							}
-							*list = (*list)[:bidsearch.SearchPageSize_APP]
+							if list != nil {
+								list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
+							} else {
+								list = secRel
+							}
+							secondFlag = "T"
+							if len(*list) > bidsearch.SearchPageSize_APP && selectType == "title" {
+								secondList = (*list)[bidsearch.SearchPageSize_APP:]
+								if len(secondList) > bidsearch.SearchPageSize_APP {
+									secondList = secondList[:bidsearch.SearchPageSize_APP]
+								}
+								*list = (*list)[:bidsearch.SearchPageSize_APP]
+							}
+						} else {
+							secondKWS = ""
 						}
-					} else {
-						secondKWS = ""
 					}
 				}
 				public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "app", "超级搜索", map[string]interface{}{

+ 11 - 9
src/jfw/modules/common/src/qfw/util/dataexport/dataexport.go

@@ -479,15 +479,17 @@ func GetDataExportSearchResult(bid mg.MongodbSim, elasticAddress string, scd *Si
 				searchTextSize = len([]rune(scd.Keyword[0].Keyword))
 			}
 			if searchTextSize > 3 && num < 50 {
-				secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", elasticAddress)
-				scd.Keyword[0].Keyword = secondKWS
-				scd.SelectType = "title"
-				qstr = getDataExportSql(scd)
-				log.Printf("GetDataExportSearchResult-%s-分词查询-sql:%s\n", scd.Id, qstr)
-				res2 := doSearch(qstr, 0, 100, "")
-				res = *delRepeatMapArr(&res, res2)
-				if len(res) > 100 {
-					res = res[:100]
+				if strings.Index(scd.SelectType, "title") > -1 {
+					secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", elasticAddress)
+					scd.Keyword[0].Keyword = secondKWS
+					scd.SelectType = "title"
+					qstr = getDataExportSql(scd)
+					log.Printf("GetDataExportSearchResult-%s-分词查询-sql:%s\n", scd.Id, qstr)
+					res2 := doSearch(qstr, 0, 100, "")
+					res = *delRepeatMapArr(&res, res2)
+					if len(res) > 100 {
+						res = res[:100]
+					}
 				}
 			}
 		}