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:
parent
efbd7ca39b
commit
3c45cf8494
20 changed files with 346 additions and 63 deletions
|
@ -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)
|
||||
|
|
|
@ -22,26 +22,30 @@ func Search(ctx *context.Context) {
|
|||
ctx.Redirect(ctx.Repo.RepoLink, 302)
|
||||
return
|
||||
}
|
||||
language := strings.TrimSpace(ctx.Query("l"))
|
||||
keyword := strings.TrimSpace(ctx.Query("q"))
|
||||
page := ctx.QueryInt("page")
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
total, searchResults, err := code_indexer.PerformSearch([]int64{ctx.Repo.Repository.ID},
|
||||
keyword, page, setting.UI.RepoSearchPagingNum)
|
||||
total, searchResults, searchResultLanguages, err := code_indexer.PerformSearch([]int64{ctx.Repo.Repository.ID},
|
||||
language, keyword, page, setting.UI.RepoSearchPagingNum)
|
||||
if err != nil {
|
||||
ctx.ServerError("SearchResults", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Language"] = language
|
||||
ctx.Data["SourcePath"] = setting.AppSubURL + "/" +
|
||||
path.Join(ctx.Repo.Repository.Owner.Name, ctx.Repo.Repository.Name, "src", "branch", ctx.Repo.Repository.DefaultBranch)
|
||||
path.Join(ctx.Repo.Repository.Owner.Name, ctx.Repo.Repository.Name)
|
||||
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, tplSearch)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue