浏览代码

fix:关键词匹配修改

duxin 2 年之前
父节点
当前提交
b7bd5e065b
共有 2 个文件被更改,包括 32 次插入28 次删除
  1. 30 26
      entity/search/advancedProject.go
  2. 2 2
      entity/search/customizedAnalysis.go

+ 30 - 26
entity/search/advancedProject.go

@@ -12,9 +12,9 @@ import (
 	"time"
 )
 
-func AdvancedProject(userid, keyWord string, types int) map[string]interface{} {
+func AdvancedProject(userid, keyWord string) map[string]interface{} {
 	mae := new(MarketAnalysisEntity)
-	if !mae.KeyWordFormat(userid, keyWord, types) {
+	if !mae.KeyWordFormat(userid, keyWord) {
 		log.Printf("关键词格式化化失败 userid:%s", userid)
 		return nil
 	}
@@ -73,9 +73,8 @@ func AdvancedProject(userid, keyWord string, types int) map[string]interface{} {
 	}
 }
 
-func (mae *MarketAnalysisEntity) KeyWordFormat(userid, keyWord string, types int) (ret bool) {
+func (mae *MarketAnalysisEntity) KeyWordFormat(userid, keyWord string) (ret bool) {
 	var (
-		arrMap []map[string]interface{}
 		aItems []interface{}
 	)
 	switch mae.Types {
@@ -83,36 +82,25 @@ func (mae *MarketAnalysisEntity) KeyWordFormat(userid, keyWord string, types int
 		//获取订阅词
 		aItems, ret = Subscription(userid)
 		//无订阅词且未搜索页面 查询搜索词
-		if !ret && types == 1 {
+		if !ret {
 			arrs := strings.Split(redis.GetStr("other", "s_"+userid), ",")
-			if len(arrs) > 3 {
-				arrs = arrs[:3]
-			}
-			if len(arrs) > 0 {
+			if len(arrs) == 0 && keyWord != "" {
+				//无缓存搜索词
 				ret = true
-				for _, v := range arrs {
-					arrMap = append(arrMap, map[string]interface{}{"from": 1, "appendkey": nil, "key": processKeyword(v), "notkey": nil, "updatetime": time.Now().Unix()})
-				}
-				item := map[string]interface{}{
-					"a_key":      arrMap,
-					"s_item":     "未分类",
-					"updatetime": time.Now().Unix(),
+				aItems = KeyFormat(strings.Split(keyWord, ","))
+			} else {
+				ret = true
+				//有缓存搜索词 取最近3个
+				if len(arrs) > 3 {
+					arrs = arrs[:3]
 				}
-				aItems = append(aItems, item)
+				aItems = KeyFormat(arrs)
 			}
 		}
 	case 2: //超前项目
 		if keyWord != "" { //搜索页面超前项目
 			ret = true
-			for _, v := range strings.Split(keyWord, ",") {
-				arrMap = append(arrMap, map[string]interface{}{"from": 1, "appendkey": nil, "key": processKeyword(v), "notkey": nil, "updatetime": time.Now().Unix()})
-			}
-			item := map[string]interface{}{
-				"a_key":      arrMap,
-				"s_item":     "未分类",
-				"updatetime": time.Now().Unix(),
-			}
-			aItems = append(aItems, item)
+			aItems = KeyFormat(strings.Split(keyWord, ","))
 		} else { //没有关键词 订阅页面超前项目
 			//未传搜索词按照关键词匹配
 			aItems, ret = Subscription(userid)
@@ -130,6 +118,22 @@ func (mae *MarketAnalysisEntity) KeyWordFormat(userid, keyWord string, types int
 	return
 }
 
+func KeyFormat(keyWord []string) (aItems []interface{}) {
+	var arrMap []map[string]interface{}
+	for _, v := range keyWord {
+		arrMap = append(arrMap, map[string]interface{}{"from": 1, "appendkey": nil, "key": processKeyword(v), "notkey": nil, "updatetime": time.Now().Unix()})
+	}
+	if len(arrMap) > 0 {
+		item := map[string]interface{}{
+			"a_key":      arrMap,
+			"s_item":     "未分类",
+			"updatetime": time.Now().Unix(),
+		}
+		aItems = append(aItems, item)
+	}
+	return
+}
+
 func Subscription(userid string) (aItems []interface{}, ret bool) {
 	var arrMap []map[string]interface{}
 	//未传搜索词按照关键词匹配

+ 2 - 2
entity/search/customizedAnalysis.go

@@ -11,9 +11,9 @@ import (
 
 var Analysis = []string{"<10万", "10万-50万", "50万-100万", "100万-500万", "500万-1000万", "1000万-1亿", "≥1亿"}
 
-func PotentialCustomizeAnalysis(userid, keyWord string, types int) map[string]interface{} {
+func PotentialCustomizeAnalysis(userid, keyWord string) map[string]interface{} {
 	mae := new(MarketAnalysisEntity)
-	if !mae.KeyWordFormat(userid, keyWord, types) {
+	if !mae.KeyWordFormat(userid, keyWord) {
 		log.Printf("关键词格式化化失败 userid:%s", userid)
 		return nil
 	}