|
@@ -342,130 +342,150 @@ func (this *SearchController) ListHomeArtAndChart() {
|
|
|
this.Data["json"] = br
|
|
|
this.ServeJSON()
|
|
|
}()
|
|
|
- //pageSize, _ := this.GetInt("PageSize")
|
|
|
- //currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
- //listType, _ := this.GetInt("ListType")
|
|
|
- //var startSize int
|
|
|
- //if pageSize <= 0 {
|
|
|
- // pageSize = utils.PageSize20
|
|
|
- //}
|
|
|
- //if currentIndex <= 0 {
|
|
|
- // currentIndex = 1
|
|
|
- //}
|
|
|
- //startSize = paging.StartIndex(currentIndex, pageSize)
|
|
|
- //keyWord := this.GetString("KeyWord")
|
|
|
- //orderColumn := this.GetString("OrderColumn")
|
|
|
- //if keyWord == "" {
|
|
|
- // br.Msg = "请输入搜索词"
|
|
|
- // br.ErrMsg = "请输入搜索词"
|
|
|
- // return
|
|
|
- //}
|
|
|
- //user := this.User
|
|
|
- //if user == nil {
|
|
|
- // br.Msg = "请重新登录"
|
|
|
- // br.Ret = 408
|
|
|
- // return
|
|
|
- //}
|
|
|
- //
|
|
|
- ////研选的五张图片
|
|
|
- //detailResearch, errConfig := models.GetConfigByCode("category_research_img_url")
|
|
|
- //if errConfig != nil {
|
|
|
- // br.Msg = "获取数据失败"
|
|
|
- // br.ErrMsg = "获取数据研选分类图片失败,Err:" + errConfig.Error()
|
|
|
- // return
|
|
|
- //}
|
|
|
- //researchList := strings.Split(detailResearch.ConfigValue, "{|}")
|
|
|
- ////对应分类的所图片
|
|
|
- //detailCategoryUrl, errConfig := models.GetConfigByCode("category_map_img_url")
|
|
|
- //if errConfig != nil {
|
|
|
- // br.Msg = "获取数据失败"
|
|
|
- // br.ErrMsg = "行业配置信息失败,Err:" + errConfig.Error()
|
|
|
- // return
|
|
|
- //}
|
|
|
- //categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
|
|
|
- //mapCategoryUrl := make(map[string]string)
|
|
|
- //var categoryId string
|
|
|
- //var imgUrlChart string
|
|
|
- //for _, v := range categoryUrlList {
|
|
|
- // vslice := strings.Split(v, "_")
|
|
|
- // categoryId = vslice[0]
|
|
|
- // imgUrlChart = vslice[len(vslice)-1]
|
|
|
- // mapCategoryUrl[categoryId] = imgUrlChart
|
|
|
- //}
|
|
|
- //if orderColumn == "" {
|
|
|
- // orderColumn = "Matching"
|
|
|
- //}
|
|
|
- //indexName := utils.IndexName
|
|
|
- //
|
|
|
- //var total, chartTotal int
|
|
|
- //resp := new(models.HomeArtAndChartListResp)
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ listType, _ := this.GetInt("ListType")
|
|
|
+ var startSize int
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = paging.StartIndex(currentIndex, pageSize)
|
|
|
+ keyWord := this.GetString("KeyWord")
|
|
|
+ orderColumn := this.GetString("OrderColumn")
|
|
|
+ if keyWord == "" {
|
|
|
+ br.Msg = "请输入搜索词"
|
|
|
+ br.ErrMsg = "请输入搜索词"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请重新登录"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //研选的五张图片
|
|
|
+ detailResearch, errConfig := models.GetConfigByCode("category_research_img_url")
|
|
|
+ if errConfig != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据研选分类图片失败,Err:" + errConfig.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ researchList := strings.Split(detailResearch.ConfigValue, "{|}")
|
|
|
+ //对应分类的所图片
|
|
|
+ detailCategoryUrl, errConfig := models.GetConfigByCode("category_map_img_url")
|
|
|
+ if errConfig != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "行业配置信息失败,Err:" + errConfig.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
|
|
|
+ mapCategoryUrl := make(map[string]string)
|
|
|
+ var categoryId string
|
|
|
+ var imgUrlChart string
|
|
|
+ for _, v := range categoryUrlList {
|
|
|
+ vslice := strings.Split(v, "_")
|
|
|
+ categoryId = vslice[0]
|
|
|
+ imgUrlChart = vslice[len(vslice)-1]
|
|
|
+ mapCategoryUrl[categoryId] = imgUrlChart
|
|
|
+ }
|
|
|
+ if orderColumn == "" {
|
|
|
+ orderColumn = "Matching"
|
|
|
+ }
|
|
|
+ indexName := utils.IndexName
|
|
|
+
|
|
|
+ var chartTotal int
|
|
|
+ resp := new(models.SearchResp)
|
|
|
//page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
- //resp.HaveResearch = true
|
|
|
- //var chartList []*models.HomeChartListResp
|
|
|
- //var err error
|
|
|
- //if listType == 1 {
|
|
|
- // if currentIndex <= 2 {
|
|
|
- // chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
|
|
|
- // if err != nil {
|
|
|
- // br.Msg = "获取信息失败"
|
|
|
- // br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
|
|
|
- // return
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
+ var chartList []*models.HomeChartListResp
|
|
|
+ var err error
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ if listType == 1 || listType == 3 {
|
|
|
+ if currentIndex <= 2 {
|
|
|
+ condition = ` AND title LIKE '%` + keyWord + `%'`
|
|
|
+ if listType == 1 {
|
|
|
+ pageSize = 100
|
|
|
+ }
|
|
|
+ chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartTotal, err = models.GetChartCount(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.Msg = "获取帖子总数失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for k, _ := range chartList {
|
|
|
+ chartList[k].IsNeedJump = true
|
|
|
+ chartList[k].Source = 2
|
|
|
+ }
|
|
|
+ resp.ChartList = chartList
|
|
|
+ var result []*models.SearchItem
|
|
|
+ var total int64
|
|
|
+ if listType == 1 || listType == 2 {
|
|
|
+ if orderColumn == "PublishDate" {
|
|
|
+ tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, user.UserId)
|
|
|
+ result = tmpResult
|
|
|
+ total = tmpTotal
|
|
|
+ err = tmpErr
|
|
|
+ } else {
|
|
|
+ tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, user.UserId, orderColumn)
|
|
|
+ result = tmpResult
|
|
|
+ total = tmpTotal
|
|
|
+ err = tmpErr
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "检索失败"
|
|
|
+ br.ErrMsg = "检索失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(result) == 0 {
|
|
|
+ result = make([]*models.SearchItem, 0)
|
|
|
+ }
|
|
|
|
|
|
- //var result []*models.SearchItem
|
|
|
- //var total int64
|
|
|
- //var err error
|
|
|
- //if orderColumn == "PublishDate" {
|
|
|
- // tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, user.UserId)
|
|
|
- // result = tmpResult
|
|
|
- // total = tmpTotal
|
|
|
- // err = tmpErr
|
|
|
- //} else {
|
|
|
- // tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, user.UserId, orderColumn)
|
|
|
- // result = tmpResult
|
|
|
- // total = tmpTotal
|
|
|
- // err = tmpErr
|
|
|
- //}
|
|
|
- //if err != nil {
|
|
|
- // br.Msg = "检索失败"
|
|
|
- // br.ErrMsg = "检索失败,Err:" + err.Error()
|
|
|
- // return
|
|
|
- //}
|
|
|
- //if len(result) == 0 {
|
|
|
- // result = make([]*models.SearchItem, 0)
|
|
|
- //}
|
|
|
- //detail, errKey := models.GetNewSearchKeyWordByThisUser(user.UserId, keyWord)
|
|
|
- //if errKey != nil && errKey.Error() != utils.ErrNoRow() {
|
|
|
- // br.Msg = "获取信息失败"
|
|
|
- // br.ErrMsg = "获取信息失败,Err:" + errKey.Error()
|
|
|
- // return
|
|
|
- //}
|
|
|
- ////同一个用户一分钟之内搜索的词不重复记录
|
|
|
- //if detail == nil || time.Now().After(detail.CreateTime.Add(+time.Minute*1)) {
|
|
|
- // //fmt.Println("一分钟之内没有搜索")
|
|
|
- // keyWordItem := new(models.CygxSearchKeyWord)
|
|
|
- // keyWordItem.UserId = user.UserId
|
|
|
- // keyWordItem.KeyWord = keyWord
|
|
|
- // keyWordItem.CreateTime = time.Now()
|
|
|
- // go models.AddSearchKeyWord(keyWordItem)
|
|
|
- //}
|
|
|
- //for k, v := range result {
|
|
|
- // //如果是研选系列的任意取五张图片的中的一张
|
|
|
- // if v.CategoryId == "0" {
|
|
|
- // knum := v.ArticleId % 5
|
|
|
- // result[k].ImgUrlPc = researchList[knum]
|
|
|
- // } else {
|
|
|
- // result[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
|
|
|
- // }
|
|
|
- //}
|
|
|
- ////resp := new(models.SearchResp)
|
|
|
- ////page := paging.GetPaging(currentIndex, pageSize, int(total))
|
|
|
- ////resp.Paging = page
|
|
|
- ////resp.List = result
|
|
|
+ for k, v := range result {
|
|
|
+ //如果是研选系列的任意取五张图片的中的一张
|
|
|
+ if v.CategoryId == "0" {
|
|
|
+ knum := v.ArticleId % 5
|
|
|
+ result[k].ImgUrlPc = researchList[knum]
|
|
|
+ } else {
|
|
|
+ result[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
|
|
|
+ }
|
|
|
+ result[k].Source = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail, errKey := models.GetNewSearchKeyWordByThisUser(user.UserId, keyWord)
|
|
|
+ if errKey != nil && errKey.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取信息失败,Err:" + errKey.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //同一个用户一分钟之内搜索的词不重复记录
|
|
|
+ if detail == nil || time.Now().After(detail.CreateTime.Add(+time.Minute*1)) {
|
|
|
+ //fmt.Println("一分钟之内没有搜索")
|
|
|
+ keyWordItem := new(models.CygxSearchKeyWord)
|
|
|
+ keyWordItem.UserId = user.UserId
|
|
|
+ keyWordItem.KeyWord = keyWord
|
|
|
+ keyWordItem.CreateTime = time.Now()
|
|
|
+ go models.AddSearchKeyWord(keyWordItem)
|
|
|
+ }
|
|
|
+ if chartTotal > int(total) {
|
|
|
+ total = int64(chartTotal)
|
|
|
+ }
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, int(total))
|
|
|
+ resp.Paging = page
|
|
|
+ resp.List = result
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
- //br.Data = resp
|
|
|
+ br.Data = resp
|
|
|
}
|