浏览代码

no message

zhangchuanxing 2 天之前
父节点
当前提交
7113be4566
共有 3 个文件被更改,包括 18 次插入10 次删除
  1. 6 4
      controllers/config.go
  2. 4 4
      controllers/search.go
  3. 8 2
      models/search_key_word.go

+ 6 - 4
controllers/config.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
+	"hongze/hongze_cygx/utils"
 	"strings"
 	"time"
 )
@@ -36,6 +37,7 @@ func (this *ConfigController) BrowseHistoryList() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
+	strings.Replace(hotSearch, "/", ",", -1)
 
 	chartList, err := models.GetChartListConfig()
 	if err != nil {
@@ -50,10 +52,10 @@ func (this *ConfigController) 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 = "获取信息失败"

+ 4 - 4
controllers/search.go

@@ -602,10 +602,10 @@ func (this *SearchController) ListHomeArtAndChartPage() {
 	if listType == 1 || listType == 2 {
 		//添加映射关系
 		keyWord = strings.ToUpper(keyWord)
-		keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
-		if keyWordDetail != nil {
-			keyWord = keyWordDetail.KeyWordMap
-		}
+		//keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
+		//if keyWordDetail != nil {
+		//	keyWord = keyWordDetail.KeyWordMap
+		//}
 		_, tmpTotal, err := services.EsArticleSearch(keyWord, startSize, pageSize, orderColumn, 0)
 		if err != nil {
 			br.Msg = "检索失败"

+ 8 - 2
models/search_key_word.go

@@ -36,11 +36,17 @@ 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
 }
-
 func GetCygxSearchKeyWordList(condition string) (items []*CygxSearchKeyWord, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM cygx_search_key_word_log   WHERE 1 = 1 ` + condition + `  GROUP BY user_id  `