|
@@ -32,23 +32,50 @@ func (stdDoc *StdDoc) Search() {
|
|
sort := stdDoc.GetString("sort") //排序 tSort dSort vSort
|
|
sort := stdDoc.GetString("sort") //排序 tSort dSort vSort
|
|
pageNumReq, _ := stdDoc.GetInt("num") //页码 从1开始
|
|
pageNumReq, _ := stdDoc.GetInt("num") //页码 从1开始
|
|
pageSizeReq, _ := stdDoc.GetInt("size") //每页数量
|
|
pageSizeReq, _ := stdDoc.GetInt("size") //每页数量
|
|
|
|
+ productType, _ := stdDoc.GetInt("productType") //每页数量
|
|
|
|
+ docFileType, _ := stdDoc.GetInt("docFileType") //每页数量
|
|
pageNum, pageSize, err := public.PageNumParse(pageNumReq, pageSizeReq, config.JyDocsAppConfig.SearchNumLimit)
|
|
pageNum, pageSize, err := public.PageNumParse(pageNumReq, pageSizeReq, config.JyDocsAppConfig.SearchNumLimit)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
- if keyWord == "" {
|
|
|
|
|
|
+ if keyWord == "" && tag == "" && productType == 0 {
|
|
return nil, fmt.Errorf("检索内容不能为空")
|
|
return nil, fmt.Errorf("检索内容不能为空")
|
|
}
|
|
}
|
|
if tag == "全部" {
|
|
if tag == "全部" {
|
|
tag = ""
|
|
tag = ""
|
|
}
|
|
}
|
|
- list, total, err := rpc.GetDocQuery(userId, keyWord, tag, pageNum, pageSize, sort)
|
|
|
|
|
|
+ if keyWord == "" && (pageNum > 1 || pageSize > 50 || docFileType != 0) { // / 搜索时关键词不能为空 热门推荐 会员免费 精选推荐时关键词可以为空所以再判断一下页数
|
|
|
|
+ return nil, fmt.Errorf("参数有误")
|
|
|
|
+ }
|
|
|
|
+ // 关键词为空说明不是搜索过来的
|
|
|
|
+ topKey := fmt.Sprintf("jydoc_searchCache_%s_%d_%s_%d_%d", tag, productType, sort, pageNum, pageSize)
|
|
|
|
+ if keyWord == "" {
|
|
|
|
+ listCache := redis.Get("other", topKey)
|
|
|
|
+ if listCache != nil {
|
|
|
|
+ return listCache, nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ list, total, err := rpc.GetDocQuery(userId, keyWord, tag, pageNum, pageSize, sort, productType, docFileType)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
if total > config.JyDocsAppConfig.SearchNumLimit {
|
|
if total > config.JyDocsAppConfig.SearchNumLimit {
|
|
total = config.JyDocsAppConfig.SearchNumLimit
|
|
total = config.JyDocsAppConfig.SearchNumLimit
|
|
}
|
|
}
|
|
|
|
+ returnList := []interface{}{}
|
|
|
|
+ for _, v := range list {
|
|
|
|
+ //
|
|
|
|
+ if v.Source == public.SourceDd {
|
|
|
|
+ v.PreviewImgId = fmt.Sprintf(config.JyDocsAppConfig.DoudingImg, v.DocId)
|
|
|
|
+ } else {
|
|
|
|
+ v.PreviewImgId = fmt.Sprintf("https://%s.%s/%s", config.JyDocsAppConfig.OssBucket.Priv, config.JyDocsAppConfig.OssAdmin, v.PreviewImgId)
|
|
|
|
+ }
|
|
|
|
+ returnList = append(returnList, v)
|
|
|
|
+ }
|
|
|
|
+ // 存缓存
|
|
|
|
+ if keyWord == "" && len(returnList) > 0 {
|
|
|
|
+ redis.Put("other", topKey, list, 60*60*2)
|
|
|
|
+ }
|
|
return map[string]interface{}{
|
|
return map[string]interface{}{
|
|
"total": total,
|
|
"total": total,
|
|
"list": list,
|
|
"list": list,
|
|
@@ -61,7 +88,8 @@ func (stdDoc *StdDoc) Search() {
|
|
}
|
|
}
|
|
|
|
|
|
func (stdDoc *StdDoc) IndexTag() {
|
|
func (stdDoc *StdDoc) IndexTag() {
|
|
- stdDoc.ServeJson(NewResult(config.JyDocsAppConfig.IndexSearchTag, nil))
|
|
|
|
|
|
+ tags, err := rpc.GetIndexTags()
|
|
|
|
+ stdDoc.ServeJson(NewResult(tags, err))
|
|
}
|
|
}
|
|
|
|
|
|
func (stdDoc *StdDoc) Detail() {
|
|
func (stdDoc *StdDoc) Detail() {
|
|
@@ -106,7 +134,7 @@ func (stdDoc *StdDoc) Recommend() {
|
|
if strings.Index(docTag, ",") > -1 {
|
|
if strings.Index(docTag, ",") > -1 {
|
|
docTag = strings.Split(docTag, ",")[0]
|
|
docTag = strings.Split(docTag, ",")[0]
|
|
}
|
|
}
|
|
- list, _, err := rpc.GetDocQuery(userId, "", docTag, 1, num+1, "dSort")
|
|
|
|
|
|
+ list, _, err := rpc.GetDocQuery(userId, "", docTag, 1, num+1, "dSort", 0, 0)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -182,7 +210,7 @@ func (stdDoc *StdDoc) TopList() {
|
|
return listCache, nil
|
|
return listCache, nil
|
|
}
|
|
}
|
|
log.Println("flush", topKey)
|
|
log.Println("flush", topKey)
|
|
- list, _, err := rpc.GetDocQuery(userId, "", "", 1, num, reqSort)
|
|
|
|
|
|
+ list, _, err := rpc.GetDocQuery(userId, "", "", 1, num, reqSort, 0, 0)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|