diff options
author | Lauris BH <lauris@nix.lv> | 2020-02-20 21:53:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-20 16:53:55 -0300 |
commit | 3c45cf8494fcd29e1a99b0ee6f253808eb607053 (patch) | |
tree | cd0e6347bcd2bfc42c18408169a8757ca1dda920 /routers/home.go | |
parent | efbd7ca39bde69ff84d4b309bee99edfe2977521 (diff) | |
download | gitea-3c45cf8494fcd29e1a99b0ee6f253808eb607053.tar.gz gitea-3c45cf8494fcd29e1a99b0ee6f253808eb607053.zip |
Add detected file language to code search (#10256)
Move langauge detection to separate module to be more reusable
Add option to disable vendored file exclusion from file search
Allways show all language stats for search
Diffstat (limited to 'routers/home.go')
-rw-r--r-- | routers/home.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/routers/home.go b/routers/home.go index 77a7e153e2..1b8c4cd17b 100644 --- a/routers/home.go +++ b/routers/home.go @@ -290,6 +290,7 @@ func ExploreCode(ctx *context.Context) { ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreCode"] = true + language := strings.TrimSpace(ctx.Query("l")) keyword := strings.TrimSpace(ctx.Query("q")) page := ctx.QueryInt("page") if page <= 0 { @@ -317,8 +318,9 @@ func ExploreCode(ctx *context.Context) { } var ( - total int - searchResults []*code_indexer.Result + total int + searchResults []*code_indexer.Result + searchResultLanguages []*code_indexer.SearchResultLanguages ) // if non-admin login user, we need check UnitTypeCode at first @@ -340,14 +342,14 @@ func ExploreCode(ctx *context.Context) { ctx.Data["RepoMaps"] = rightRepoMap - total, searchResults, err = code_indexer.PerformSearch(repoIDs, keyword, page, setting.UI.RepoSearchPagingNum) + total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum) if err != nil { ctx.ServerError("SearchResults", err) return } // if non-login user or isAdmin, no need to check UnitTypeCode } else if (ctx.User == nil && len(repoIDs) > 0) || isAdmin { - total, searchResults, err = code_indexer.PerformSearch(repoIDs, keyword, page, setting.UI.RepoSearchPagingNum) + total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum) if err != nil { ctx.ServerError("SearchResults", err) return @@ -377,12 +379,15 @@ func ExploreCode(ctx *context.Context) { } ctx.Data["Keyword"] = keyword + ctx.Data["Language"] = language ctx.Data["SearchResults"] = searchResults + ctx.Data["SearchResultLanguages"] = searchResultLanguages ctx.Data["RequireHighlightJS"] = true ctx.Data["PageIsViewCode"] = true pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5) pager.SetDefaultParams(ctx) + pager.AddParam(ctx, "l", "Language") ctx.Data["Page"] = pager ctx.HTML(200, tplExploreCode) |