本站源代码
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

49 行
1.3KB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "path"
  7. "strings"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/search"
  11. "code.gitea.io/gitea/modules/setting"
  12. )
  13. const tplSearch base.TplName = "repo/search"
  14. // Search render repository search page
  15. func Search(ctx *context.Context) {
  16. if !setting.Indexer.RepoIndexerEnabled {
  17. ctx.Redirect(ctx.Repo.RepoLink, 302)
  18. return
  19. }
  20. keyword := strings.TrimSpace(ctx.Query("q"))
  21. page := ctx.QueryInt("page")
  22. if page <= 0 {
  23. page = 1
  24. }
  25. total, searchResults, err := search.PerformSearch([]int64{ctx.Repo.Repository.ID},
  26. keyword, page, setting.UI.RepoSearchPagingNum)
  27. if err != nil {
  28. ctx.ServerError("SearchResults", err)
  29. return
  30. }
  31. ctx.Data["Keyword"] = keyword
  32. ctx.Data["SourcePath"] = setting.AppSubURL + "/" +
  33. path.Join(ctx.Repo.Repository.Owner.Name, ctx.Repo.Repository.Name, "src", "branch", ctx.Repo.Repository.DefaultBranch)
  34. ctx.Data["SearchResults"] = searchResults
  35. ctx.Data["RequireHighlightJS"] = true
  36. ctx.Data["PageIsViewCode"] = true
  37. pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
  38. pager.SetDefaultParams(ctx)
  39. ctx.Data["Page"] = pager
  40. ctx.HTML(200, tplSearch)
  41. }
上海开阖软件有限公司 沪ICP备12045867号-1