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 /modules/indexer/code/search.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 'modules/indexer/code/search.go')
-rw-r--r-- | modules/indexer/code/search.go | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/modules/indexer/code/search.go b/modules/indexer/code/search.go index 18f193a532..ca57b3ff88 100644 --- a/modules/indexer/code/search.go +++ b/modules/indexer/code/search.go @@ -11,6 +11,7 @@ import ( "strings" "code.gitea.io/gitea/modules/highlight" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" ) @@ -18,6 +19,10 @@ import ( type Result struct { RepoID int64 Filename string + CommitID string + UpdatedUnix timeutil.TimeStamp + Language string + Color string HighlightClass string LineNumbers []int FormattedLines gotemplate.HTML @@ -100,6 +105,10 @@ func searchResult(result *SearchResult, startIndex, endIndex int) (*Result, erro return &Result{ RepoID: result.RepoID, Filename: result.Filename, + CommitID: result.CommitID, + UpdatedUnix: result.UpdatedUnix, + Language: result.Language, + Color: result.Color, HighlightClass: highlight.FileNameToHighlightClass(result.Filename), LineNumbers: lineNumbers, FormattedLines: gotemplate.HTML(formattedLinesBuffer.String()), @@ -107,14 +116,14 @@ func searchResult(result *SearchResult, startIndex, endIndex int) (*Result, erro } // PerformSearch perform a search on a repository -func PerformSearch(repoIDs []int64, keyword string, page, pageSize int) (int, []*Result, error) { +func PerformSearch(repoIDs []int64, language, keyword string, page, pageSize int) (int, []*Result, []*SearchResultLanguages, error) { if len(keyword) == 0 { - return 0, nil, nil + return 0, nil, nil, nil } - total, results, err := indexer.Search(repoIDs, keyword, page, pageSize) + total, results, resultLanguages, err := indexer.Search(repoIDs, language, keyword, page, pageSize) if err != nil { - return 0, nil, err + return 0, nil, nil, err } displayResults := make([]*Result, len(results)) @@ -123,8 +132,8 @@ func PerformSearch(repoIDs []int64, keyword string, page, pageSize int) (int, [] startIndex, endIndex := indices(result.Content, result.StartIndex, result.EndIndex) displayResults[i], err = searchResult(result, startIndex, endIndex) if err != nil { - return 0, nil, err + return 0, nil, nil, err } } - return int(total), displayResults, nil + return int(total), displayResults, resultLanguages, nil } |