zhangchuanxing 1 сар өмнө
parent
commit
f383af6750

+ 8 - 8
controllers/search.go

@@ -61,10 +61,10 @@ func (this *MobileSearchController) ListHomeArtAndChart() {
 	}
 	//添加映射关系
 	keyWord = strings.ToUpper(keyWord)
-	keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
-	if keyWordDetail != nil {
-		keyWord = keyWordDetail.KeyWordMap
-	}
+	//keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
+	//if keyWordDetail != nil {
+	//	keyWord = keyWordDetail.KeyWordMap
+	//}
 	user := this.User
 	if user == nil {
 		br.Msg = "请重新登录"
@@ -326,10 +326,10 @@ func (this *MobileSearchController) BrowseHistoryList() {
 	}
 	var condition string
 	var pars []interface{}
-	currentTime := time.Now()
-	starTime := currentTime.AddDate(0, 0, -8).Format("2006-01-02") + " 00:00:00"
-	endTime := currentTime.AddDate(0, 0, -1).Format("2006-01-02") + " 23:59:59"
-	condition += ` AND create_time < ` + "'" + endTime + "'" + `AND create_time > ` + "'" + starTime + "'"
+	starTime := time.Now().AddDate(0, 0, -8).Format(utils.FormatDate)
+	endTime := time.Now().Format(utils.FormatDate)
+	condition += ` AND create_time > ? AND create_time < ?  AND user_id > 0 `
+	pars = append(pars, starTime, endTime)
 	hotList, err := models.GetSearchKeyWordTop(condition, pars)
 	if err != nil {
 		br.Msg = "获取信息失败"

+ 8 - 1
models/search_key_word.go

@@ -36,7 +36,14 @@ func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKey
 // 获取用户搜索词汇频率较高的词
 func GetSearchKeyWordTop(condition string, pars []interface{}) (items []*CygxSearchKeyWord, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT key_word, MAX(create_time) as create_time, COUNT(*) AS num FROM cygx_search_key_word  WHERE 1=1  ` + condition + ` GROUP BY key_word ORDER BY num DESC,create_time DESC LIMIT 12 `
+	sql := `SELECT
+				key_word,
+				MAX(id) as max_id ,
+				COUNT( DISTINCT user_id ) AS unique_user_searches 
+			FROM
+				cygx_search_key_word 
+			WHERE
+				1 = 1 ` + condition + ` GROUP BY key_word ORDER BY unique_user_searches DESC, max_id DESC LIMIT 12 `
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }