Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 4 years ago
parent
commit
b0ebff2806
2 changed files with 25 additions and 13 deletions
  1. +10
    -4
      models/search_record.go
  2. +15
    -9
      routers/search.go

+ 10
- 4
models/search_record.go View File

@@ -3,6 +3,7 @@ package models
import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/xorm"
)

type SearchRecord struct {
@@ -27,18 +28,23 @@ func SaveSearchKeywordToDb(keyword string) error {
return nil
}

func SearchPrivateIssueOrPr(Page int, PageSize int, Keyword string, isPull bool, userId int64) ([]*Issue, int64, error) {
sess := x.NewSession()
defer sess.Close()

func setQueryCondition(sess *xorm.Session, Keyword string, isPull bool, userId int64) {
sess.And("issue.poster_id=?", userId)
sess.And("issue.is_pull=?", isPull)
sess.And("(issue.name like '%" + Keyword + "%' or issue.content like '%" + Keyword + "%')")
sess.Join("INNER", "repository", "issue.repo_id = repository.id").And("repository.is_private = ?", true)
}

func SearchPrivateIssueOrPr(Page int, PageSize int, Keyword string, isPull bool, userId int64) ([]*Issue, int64, error) {
sess := x.NewSession()
defer sess.Close()
setQueryCondition(sess, Keyword, isPull, userId)
count, err := sess.Count(new(Issue))
if err != nil {
return nil, 0, err
}

//setQueryCondition(sess, Keyword, isPull, userId)
sess.Desc("issue.created_unix")
sess.Limit(PageSize, (Page-1)*PageSize)
issues := make([]*Issue, 0)


+ 15
- 9
routers/search.go View File

@@ -145,9 +145,11 @@ func searchRepoByLabel(ctx *context.Context, Key string, Page int, PageSize int)
log.Info("not found private repo,keyword=" + Key)
}
if repos.Len() >= PageSize {
resultObj.Total = int64(WebTotal)
ctx.JSON(200, resultObj)
return
if WebTotal > 0 {
resultObj.Total = int64(WebTotal)
ctx.JSON(200, resultObj)
return
}
}
} else {
if ctx.User == nil {
@@ -250,9 +252,11 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa
log.Info("not found private repo,keyword=" + Key)
}
if repos.Len() >= PageSize {
resultObj.Total = int64(WebTotal)
ctx.JSON(200, resultObj)
return
if WebTotal > 0 {
resultObj.Total = int64(WebTotal)
ctx.JSON(200, resultObj)
return
}
}
} else {
if ctx.User == nil {
@@ -767,9 +771,11 @@ func searchIssue(ctx *context.Context, TableName string, Key string, Page int, P
log.Info("not found private repo issue,keyword=" + Key)
}
if issuesSize >= PageSize {
resultObj.Total = int64(WebTotal)
ctx.JSON(200, resultObj)
return
if WebTotal > 0 { //next page, not first query.
resultObj.Total = int64(WebTotal)
ctx.JSON(200, resultObj)
return
}
}
} else {
resultObj.PrivateTotal = int64(PrivateTotal)


Loading…
Cancel
Save