mirror of
https://github.com/go-gitea/gitea
synced 2025-07-08 03:27:19 +00:00
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
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user