123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772 |
- package controllers
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/services"
- "hongze/hongze_cygx/utils"
- "strings"
- )
- 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 "搜索关键词"
- // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
- // @Success 200 {object} models.SearchItem
- // @router /list [get]
- func (this *SearchController) SearchList() {
- 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")
- 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
- pageSize = 20
- 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)
- }
- //记录用户搜索关键词
- go services.AddSearchKeyWord(user, keyWord, 1)
- 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
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- //https://blog.csdn.net/my_miuye/article/details/110496025
- //search
- // @Title 报告搜索接口
- // @Description 报告搜索接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.SearchItem
- // @router /report/list [get]
- func (this *SearchController) SearchReport() {
- 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
- }
- //indexName := "article_list"
- indexName := utils.IndexName
- pageSize = 100
- var result []*models.SearchItem
- var total int64
- var err error
- tmpResult, tmpTotal, tmpErr := services.EsSearchReport(indexName, keyWord, startSize, pageSize, user.UserId)
- 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)
- }
- //记录用户搜索关键词
- go services.AddSearchKeyWord(user, keyWord, 1)
- resp := new(models.SearchResp)
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp.Paging = page
- resp.List = result
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 搜索接口(无需token)
- // @Description 搜索接口(无需token)
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
- // @Param CompanyCode query string false "机构编号"
- // @Param CompanyName query string false "机构名称"
- // @Param Email query string false "邮箱"
- // @Param Sign query string false "加密签名"
- // @Success 200 {object} models.SearchItem
- // @router /listPublic [get]
- func (this *BaseSearchController) SearchListPublic() {
- 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")
- orderColumn := this.GetString("OrderColumn")
- if keyWord == "" {
- br.Msg = "请输入搜索词"
- br.ErrMsg = "请输入搜索词"
- return
- }
- companyCode := this.GetString("CompanyCode")
- companyNameHt := this.GetString("CompanyName")
- email := this.GetString("Email")
- sign := this.GetString("Sign")
- if orderColumn == "" {
- orderColumn = "Matching"
- }
- indexName := utils.IndexName
- pageSize = 20
- var result []*models.SearchItem
- var total int64
- var err error
- if orderColumn == "PublishDate" {
- tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, 0)
- result = tmpResult
- total = tmpTotal
- err = tmpErr
- } else {
- tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, 0, 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)
- }
- if companyCode != "" && companyNameHt != "" && email != "" {
- errMsg, errHt, wxUser, _ := services.CheckHtgj(companyCode, companyNameHt, email, sign)
- if errHt != nil {
- br.Msg = "获取"
- br.ErrMsg = "获取数据失败,Err:" + errHt.Error()
- return
- }
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- user := wxUser
- userItem := new(models.WxUserItem)
- userItem.UserId = user.UserId
- userItem.Mobile = user.Mobile
- userItem.Email = user.Email
- userItem.CompanyId = user.CompanyId
- userItem.RealName = user.RealName
- //记录用户搜索关键词
- go services.AddSearchKeyWord(userItem, keyWord, 1)
- }
- for k, _ := range result {
- if result[k].ArticleId < utils.SummaryArticleId {
- result[k].IsNeedJump = true
- }
- }
- resp := new(models.SearchResp)
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp.Paging = page
- resp.List = result
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 搜索接口
- // @Description 搜索接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
- // @Param ListType query int true "列表类型,1最新/全部,2 纪要 ,3图表 默认1"
- // @Success 200 {object} models.SearchItem
- // @router /artAndChart/list [get]
- func (this *SearchController) ListHomeArtAndChart() {
- br := new(models.BaseResponse).Init()
- defer func() {
- 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
- pageSize = 20
- var chartTotal int
- resp := new(models.SearchResp)
- //page := paging.GetPaging(currentIndex, pageSize, total)
- var chartList []*models.HomeChartListResp
- var err error
- var condition string
- var pars []interface{}
- if listType == 1 || listType == 3 {
- if listType == 1 {
- pageSize = 100
- }
- if currentIndex <= 2 {
- condition = ` AND title LIKE '%` + keyWord + `%'`
- 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, v := range chartList {
- chartList[k].IsNeedJump = true
- chartList[k].Source = 2
- if v.PtagName != "" {
- chartList[k].CtagNamePc = v.PtagName
- }
- if v.CtagName != "" {
- chartList[k].CtagNamePc += "," + v.CtagName
- }
- if v.PtagNameTwo != "" {
- chartList[k].CtagNamePc += "," + v.PtagNameTwo
- }
- if v.CtagNameTwo != "" {
- chartList[k].CtagNamePc += "," + v.CtagNameTwo
- }
- }
- if len(chartList) == 0 {
- chartList = make([]*models.HomeChartListResp, 0)
- }
- 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)
- }
- 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
- result[k].PublishDate = utils.StrTimeToTime(result[k].PublishDate).Format(utils.FormatDate)
- }
- }
- // ListType query int true "列表类型,1最新/全部,2 纪要 ,3图表 默认1"
- //记录用户搜索关键词
- var source int
- if listType == 1 {
- source = 3
- } else if listType == 2 {
- source = 1
- } else {
- source = 2
- }
- go services.AddSearchKeyWord(user, keyWord, source)
- if chartTotal > int(total) {
- total = int64(chartTotal)
- }
- if listType == 1 {
- total = total + int64(chartTotal)
- }
- if len(result) == 0 {
- result = make([]*models.SearchItem, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp.Paging = page
- resp.List = result
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 搜索接口
- // @Description 搜索接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
- // @Success 200 {object} models.SearchItem
- // @router /artAndChart/listPage [get]
- func (this *SearchController) ListHomeArtAndChartPage() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- // @Param ListType query int true "列表类型,1最新/全部,2 纪要 ,3图表 默认1"
- listType, _ := this.GetInt("ListType")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- listType = 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"
- }
- var chartTotal int
- resp := new(models.SearchResp)
- 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 + `%'`
- 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, v := range chartList {
- chartList[k].IsNeedJump = true
- chartList[k].Source = 2
- if v.PtagName != "" {
- chartList[k].CtagNamePc = v.PtagName
- }
- if v.CtagName != "" {
- chartList[k].CtagNamePc += "," + v.CtagName
- }
- if v.PtagNameTwo != "" {
- chartList[k].CtagNamePc += "," + v.PtagNameTwo
- }
- if v.CtagNameTwo != "" {
- chartList[k].CtagNamePc += "," + v.CtagNameTwo
- }
- }
- if len(chartList) == 0 {
- chartList = make([]*models.HomeChartListResp, 0)
- }
- resp.ChartList = chartList
- var result []*models.SearchItem
- var total int64
- var articleIds []int
- if listType == 1 || listType == 2 {
- //添加映射关系
- keyWord = strings.ToUpper(keyWord)
- keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
- if keyWordDetail != nil {
- keyWord = keyWordDetail.KeyWordMap
- }
- _, tmpTotal, err := services.EsArticleSearch(keyWord, startSize, pageSize, orderColumn, 0)
- if err != nil {
- br.Msg = "检索失败"
- br.ErrMsg = "检索失败,Err:" + err.Error()
- return
- }
- tmpResult, tmpTotalResult, err := services.EsArticleSearchBody(keyWord, startSize, pageSize, orderColumn, 1)
- if err != nil {
- br.Msg = "检索失败"
- br.ErrMsg = "检索失败,Err:" + err.Error()
- return
- }
- result = tmpResult
- if int(tmpTotalResult) < currentIndex*pageSize {
- startSizeBody := startSize - int(tmpTotalResult)
- if startSizeBody < 0 {
- startSizeBody = 0
- }
- var pageSizeBody int
- pageSizeBody = pageSize - len(tmpResult)
- tmpResultBody, tmpTotalBody, err := services.EsArticleSearchBody(keyWord, startSizeBody, pageSizeBody, orderColumn, 2)
- if err != nil {
- br.Msg = "检索失败"
- br.ErrMsg = "检索失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpResultBody {
- result = append(result, v)
- }
- tmpTotalResult += tmpTotalBody
- }
- if int(tmpTotalResult) < currentIndex*pageSize {
- startSizeIk := startSize - int(tmpTotalResult)
- if startSizeIk < 0 {
- startSizeIk = 0
- }
- var pageSizeIk int
- pageSizeIk = pageSize - len(result)
- tmpResultIk, _, err := services.EsArticleSearch(keyWord, startSizeIk, pageSizeIk, orderColumn, 2)
- if err != nil {
- br.Msg = "检索失败"
- br.ErrMsg = "检索失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpResultIk {
- result = append(result, v)
- }
- }
- total = tmpTotal
- if len(result) == 0 {
- result = make([]*models.SearchItem, 0)
- }
- 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
- v.PublishDate = utils.TimeRemoveHms(v.PublishDate)
- articleIds = append(articleIds, v.ArticleId)
- }
- }
- //记录用户搜索关键词
- //var source int
- //if listType == 1 {
- // source = 3
- //} else if listType == 2 {
- // source = 1
- //} else {
- // source = 2
- //}
- if chartTotal > int(total) {
- total = int64(chartTotal)
- }
- if listType == 1 {
- total = total + int64(chartTotal)
- }
- if len(result) == 0 {
- result = make([]*models.SearchItem, 0)
- } else {
- yxArticleIdMap := services.GetYxArticleIdMap(articleIds)
- articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
- for _, v := range result {
- v.IsResearch = yxArticleIdMap[v.ArticleId] // 添加是否属于研选的标识
- v.Pv = articleMapPv[v.ArticleId] // Pv
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp.Paging = page
- resp.List = result
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 综合搜索接口
- // @Description 综合搜索接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.SearchItem
- // @router /comprehensive/list [get]
- func (this *SearchController) ComprehensiveList() {
- 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.SqlComprehensiveSearch(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
- }
|