@@ -12,6 +12,7 @@ import (
12
12
"code.gitea.io/gitea/modules/git"
13
13
code_indexer "code.gitea.io/gitea/modules/indexer/code"
14
14
"code.gitea.io/gitea/modules/setting"
15
+ "code.gitea.io/gitea/routers/common"
15
16
"code.gitea.io/gitea/services/context"
16
17
)
17
18
@@ -29,18 +30,9 @@ func indexSettingToGitGrepPathspecList() (list []string) {
29
30
30
31
// Search render repository search page
31
32
func Search (ctx * context.Context ) {
32
- language := ctx .FormTrim ("l" )
33
- keyword := ctx .FormTrim ("q" )
34
-
35
- isFuzzy := ctx .FormOptionalBool ("fuzzy" ).ValueOrDefault (true )
36
-
37
- ctx .Data ["Keyword" ] = keyword
38
- ctx .Data ["Language" ] = language
39
- ctx .Data ["IsFuzzy" ] = isFuzzy
40
33
ctx .Data ["PageIsViewCode" ] = true
41
- ctx .Data ["IsRepoIndexerEnabled" ] = setting .Indexer .RepoIndexerEnabled
42
-
43
- if keyword == "" {
34
+ prepareSearch := common .PrepareCodeSearch (ctx )
35
+ if prepareSearch .Keyword == "" {
44
36
ctx .HTML (http .StatusOK , tplSearch )
45
37
return
46
38
}
@@ -57,9 +49,9 @@ func Search(ctx *context.Context) {
57
49
var err error
58
50
total , searchResults , searchResultLanguages , err = code_indexer .PerformSearch (ctx , & code_indexer.SearchOptions {
59
51
RepoIDs : []int64 {ctx .Repo .Repository .ID },
60
- Keyword : keyword ,
61
- IsKeywordFuzzy : isFuzzy ,
62
- Language : language ,
52
+ Keyword : prepareSearch . Keyword ,
53
+ IsKeywordFuzzy : prepareSearch . IsFuzzy ,
54
+ Language : prepareSearch . Language ,
63
55
Paginator : & db.ListOptions {
64
56
Page : page ,
65
57
PageSize : setting .UI .RepoSearchPagingNum ,
@@ -75,9 +67,9 @@ func Search(ctx *context.Context) {
75
67
ctx .Data ["CodeIndexerUnavailable" ] = ! code_indexer .IsAvailable (ctx )
76
68
}
77
69
} else {
78
- res , err := git .GrepSearch (ctx , ctx .Repo .GitRepo , keyword , git.GrepOptions {
70
+ res , err := git .GrepSearch (ctx , ctx .Repo .GitRepo , prepareSearch . Keyword , git.GrepOptions {
79
71
ContextLineNumber : 1 ,
80
- IsFuzzy : isFuzzy ,
72
+ IsFuzzy : prepareSearch . IsFuzzy ,
81
73
RefName : git .RefNameFromBranch (ctx .Repo .BranchName ).String (), // BranchName should be default branch or the first existing branch
82
74
PathspecList : indexSettingToGitGrepPathspecList (),
83
75
})
@@ -109,7 +101,7 @@ func Search(ctx *context.Context) {
109
101
110
102
pager := context .NewPagination (total , setting .UI .RepoSearchPagingNum , page , 5 )
111
103
pager .SetDefaultParams (ctx )
112
- pager .AddParamString ("l" , language )
104
+ pager .AddParamString ("l" , prepareSearch . Language )
113
105
ctx .Data ["Page" ] = pager
114
106
115
107
ctx .HTML (http .StatusOK , tplSearch )
0 commit comments