Browse Source

热搜关键词列表

xingzai 3 years ago
parent
commit
6dea496a53
3 changed files with 23 additions and 2 deletions
  1. 12 0
      controllers/config.go
  2. 3 2
      models/config.go
  3. 8 0
      models/search_key_word.go

+ 12 - 0
controllers/config.go

@@ -46,6 +46,18 @@ func (this *ConfigController) BrowseHistoryList() {
 		item.KeyWord = v.Title
 		item.KeyWord = v.Title
 		resp.List = append(resp.List, item)
 		resp.List = append(resp.List, item)
 	}
 	}
+
+	hotList, err := models.GetSearchKeyWordTop()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range hotList {
+		item := new(models.KeyWord)
+		item.KeyWord = v.KeyWord
+		resp.ListHot = append(resp.ListHot, item)
+	}
 	detail.ConfigValue = hotSearch
 	detail.ConfigValue = hotSearch
 	resp.Item = detail
 	resp.Item = detail
 	br.Msg = "获取成功!"
 	br.Msg = "获取成功!"

+ 3 - 2
models/config.go

@@ -24,8 +24,9 @@ func GetConfigByCode(configCode string) (item *CygxConfig, err error) {
 }
 }
 
 
 type ConfigResp struct {
 type ConfigResp struct {
-	Item *CygxConfig
-	List []*KeyWord `description:"图表搜索推荐"`
+	Item    *CygxConfig
+	List    []*KeyWord `description:"图表搜索推荐"`
+	ListHot []*KeyWord `description:"热搜关键词"`
 }
 }
 
 
 //获取是否展示限免标签
 //获取是否展示限免标签

+ 8 - 0
models/search_key_word.go

@@ -26,3 +26,11 @@ func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKey
 	err = o.Raw(sql, uid, keyWord).QueryRow(&item)
 	err = o.Raw(sql, uid, keyWord).QueryRow(&item)
 	return
 	return
 }
 }
+
+//获取用户搜索词汇频率较高的词
+func GetSearchKeyWordTop() (items []*CygxSearchKeyWord, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT key_word, COUNT(*) AS num FROM cygx_search_key_word GROUP BY key_word ORDER BY num DESC LIMIT 8 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}