1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package controllers
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/services"
- "hongze/hongze_mfyx/utils"
- )
- type SearchController struct {
- BaseAuthController
- }
- type BaseSearchController struct {
- BaseCommonController
- }
- // @Title 综合搜索接口
- // @Description 综合搜索接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.SearchItem
- // @router /list [get]
- func (this *SearchController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- if keyWord == "" {
- br.Msg = "请输入搜索词"
- br.ErrMsg = "请输入搜索词"
- return
- }
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- resp := new(models.HomeResourceDataListResp)
- tmpResult, tmpTotalResult, err := services.EsComprehensiveSearch(keyWord, startSize, pageSize)
- if err != nil {
- br.Msg = "检索失败"
- br.ErrMsg = "检索失败,Err:" + err.Error()
- return
- }
- //for _, v := range tmpResult {
- // fmt.Println(v.Title, "Title", v.IsSummary)
- //}
- list, err := services.GetResourceDataEsList(tmpResult, user)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if currentIndex == 1 {
- go services.AddSearchKeyWord(user, keyWord, 1)
- }
- resp.List = list
- page := paging.GetPaging(currentIndex, pageSize, int(tmpTotalResult))
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|