diff options
author | Lauris BH <lauris@nix.lv> | 2022-10-11 02:12:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-11 00:12:03 +0100 |
commit | b59b0cad0a550223f74add109ff13c0d2f4309f3 (patch) | |
tree | 4c4d0482ca8740390b5939c3979d1fef35cb9047 /routers/web/repo | |
parent | 3ccebf7f4044b85eef975e4544785893da763bd2 (diff) | |
download | gitea-b59b0cad0a550223f74add109ff13c0d2f4309f3.tar.gz gitea-b59b0cad0a550223f74add109ff13c0d2f4309f3.zip |
Add user/organization code search (#19977)
Fixes #19925
Screenshots:
![attels](https://user-images.githubusercontent.com/165205/173864718-fe789429-55bc-4cad-808c-9f02f335cddf.png)
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/search.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index 8f141cb149..3d1835c7c3 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -21,14 +21,27 @@ func Search(ctx *context.Context) { ctx.Redirect(ctx.Repo.RepoLink) return } + language := ctx.FormTrim("l") keyword := ctx.FormTrim("q") + + queryType := ctx.FormTrim("t") + isMatch := queryType == "match" + + ctx.Data["Keyword"] = keyword + ctx.Data["Language"] = language + ctx.Data["queryType"] = queryType + ctx.Data["PageIsViewCode"] = true + + if keyword == "" { + ctx.HTML(http.StatusOK, tplSearch) + return + } + page := ctx.FormInt("page") if page <= 0 { page = 1 } - queryType := ctx.FormTrim("t") - isMatch := queryType == "match" total, searchResults, searchResultLanguages, err := code_indexer.PerformSearch(ctx, []int64{ctx.Repo.Repository.ID}, language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch) @@ -41,13 +54,10 @@ func Search(ctx *context.Context) { } else { ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable() } - ctx.Data["Keyword"] = keyword - ctx.Data["Language"] = language - ctx.Data["queryType"] = queryType + ctx.Data["SourcePath"] = ctx.Repo.Repository.HTMLURL() ctx.Data["SearchResults"] = searchResults ctx.Data["SearchResultLanguages"] = searchResultLanguages - ctx.Data["PageIsViewCode"] = true pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5) pager.SetDefaultParams(ctx) |